Other Benchmarking Topics: pystones

This chapter has focused on code timing fundamentals that you can use on your own code, that apply to Python benchmarking in general, and that served as a common use case for developing larger examples for this book. Benchmarking Python is a broader and richer domain than so far implied, though. If you’re interested in pursuing this topic further, search the Web for links. Among the topics you’ll find:

The pystone test, for example, is based on a C language benchmark program that was translated to Python by Python original creator Guido van Rossum. It provides another way to measure the relative speeds of Python implementations, and seems to generally support our findings here:

c:\Python33\Lib\test> cd C:\python33\lib\test
c:\Python33\Lib\test> py −3 pystone.py
Pystone(1.1) time for 50000 passes = 0.685303
This machine benchmarks at 72960.4 pystones/second

c:\Python33\Lib\test> cd c:\python27\lib\test
c:\Python27\Lib\test> py −2 pystone.py
Pystone(1.1) time for 50000 passes = 0.463547
This machine benchmarks at 107864 pystones/second

c:\Python27\Lib\test> c:\pypy\pypy-1.9\pypy pystone.py
Pystone(1.1) time for 50000 passes = 0.099975
This machine benchmarks at 500125 pystones/second

Since it’s time to wrap up this chapter, this will have to suffice as independent confirmation of our tests’ results. Analyzing the meaning of pystone’s results is left as suggested exercise; its code is not identical across 3.X and 2.X, but appears to differ today only in terms of print operations and an initialization of a global. Also keep in mind that benchmarking is just one of many aspects of Python code analysis; for pointers on options in related domains (e.g., testing), see Chapter 36’s review of Python development tools.