I've written a script that will measure the execution speed of some of the math functions in python.
I have written a number of these programs over the years, yet I keep managing to lose them or not remember where they are or what I named them. So, I just wrote another one; I've attached both the code and the results of some runs on Windows 7 and Linux.
I'd be interested in seeing this thread collect a few posts of the results others get from running this script on their machines. If you choose to run the script, save it in a directory, open a shell window, cd to that directory, then type 'python python_perf.py'. You'll probably want to redirect the results to a file. I always run the program twice, then use a graphical diff tool like kdiff3 or WinMerge to look at the differences.
The script rounds the times in ns to two significant digits. Interpreting exactly what's going on takes a bit of work, as there can be overhead due to setting up function calls and type conversions. But the numbers are useful for getting a rough idea about the inherent cost of computing some python math functions. If you compare the Windows 7 and Linux results, you'll see that Linux is a bit faster for the elementary functions, probably due to better libc implementations. My system has a 2.5 GHz Intel Quad core processor.
If you have mpmath installed, the script will also print out timings for the mpmath library (see http://code.google.com/p/mpmath). You'll see that the times for mpmath's functions are orders of magnitude larger than the functions done in hardware; this shouldn't be too surprising and, unless you need to use lots of mpmath calls, you'll still get pretty good performance).
If there is a reasonable number of responses from others, I'll collect all the data and put it into a single spreadsheet.
I have written a number of these programs over the years, yet I keep managing to lose them or not remember where they are or what I named them. So, I just wrote another one; I've attached both the code and the results of some runs on Windows 7 and Linux.
I'd be interested in seeing this thread collect a few posts of the results others get from running this script on their machines. If you choose to run the script, save it in a directory, open a shell window, cd to that directory, then type 'python python_perf.py'. You'll probably want to redirect the results to a file. I always run the program twice, then use a graphical diff tool like kdiff3 or WinMerge to look at the differences.
The script rounds the times in ns to two significant digits. Interpreting exactly what's going on takes a bit of work, as there can be overhead due to setting up function calls and type conversions. But the numbers are useful for getting a rough idea about the inherent cost of computing some python math functions. If you compare the Windows 7 and Linux results, you'll see that Linux is a bit faster for the elementary functions, probably due to better libc implementations. My system has a 2.5 GHz Intel Quad core processor.
If you have mpmath installed, the script will also print out timings for the mpmath library (see http://code.google.com/p/mpmath). You'll see that the times for mpmath's functions are orders of magnitude larger than the functions done in hardware; this shouldn't be too surprising and, unless you need to use lots of mpmath calls, you'll still get pretty good performance).
If there is a reasonable number of responses from others, I'll collect all the data and put it into a single spreadsheet.
Attachments
-
8 KB Views: 26
-
3.7 KB Views: 28