diff -r 4276bf56dd72 Tools/pybench/pybench.py --- a/Tools/pybench/pybench.py Sun Dec 21 21:27:25 2008 +0100 +++ b/Tools/pybench/pybench.py Sun Dec 21 22:30:09 2008 +0100 @@ -917,7 +917,18 @@ python pybench.py -s p25.pybench -c p21. bench.load_tests(Setup, limitnames=limitnames) try: bench.calibrate() + try: + opstats = sys.getdxp() + except AttributeError: + opstats = None + else: + if isinstance(opstats[0], list): + # Opcode pairs not supported + opstats = None bench.run() + if opstats: + opstats = [new - old + for new, old in zip(sys.getdxp(), opstats)] except KeyboardInterrupt: print() print('*** KeyboardInterrupt -- Aborting') @@ -932,6 +943,26 @@ python pybench.py -s p25.pybench -c p21. bench.print_benchmark(hidenoise=hidenoise, limitnames=limitnames) + if opstats: + print('-' * LINE) + print('Opcode statistics') + print('-' * LINE) + print() + + import opcode, pprint + opstats = {opcode.opname[op]: n + for op, n in enumerate(opstats) if n > 0} + maxops = max(opstats.values()) + totalops = sum(opstats.values()) + for op, n in sorted(opstats.items(), key=operator.itemgetter(1), + reverse=True): + line = ( + ' ' + (op + ' ').ljust(22, '.') + ' ' + + ('%d (%d%%)' % (n, 100 * n // totalops)).ljust(17) + + ' ' + '+' * (34 * n // maxops)) + print(line) + print() + # Ring bell sys.stderr.write('\007') @@ -948,6 +979,6 @@ python pybench.py -s p25.pybench -c p21. reportfile, reason)) print() - + if __name__ == '__main__': PyBenchCmdline()