Simple Python Speed Benchmark

engsolnom at ipns.com engsolnom at ipns.com
Sat Jan 10 20:40:23 CET 2004


Knowing absolutely zero about benchmarks, I was interested in the posting referencing the paper by
Dr. Cowell-Shah. I was curious how long Python takes just to read and display time.clock(), soI made
the simple test below.

I was amazed at the difference in speed depending on when/how the clock times were converted to
milliseconds....almost 4 to 1...as indicated in the RESULTS below. I understand the variation in the
times is probably due to other running processes.

Any explanation?

The machine used is: P3, 1gHz, 256 meg of ram, Windows 2000, Python 2.3

Also, I did duplicate the intArithmetic (intMaz), using 1,000,000,000, as per the paper, and it
*did* take a long time. I tried a variety of ways to implement the process (while, range, xrange,
etc), and made some improvement, but not much. And of course I did see the "out of memory" message.

Norm

# THE CODE

import time

module_time_start = time.clock()

start_time_1 = time.clock()
stop_time_1  = time.clock()
print 'Test 1: ', (stop_time_1 - start_time_1) * 1000

start_time_2 = time.clock() * 1000
stop_time_2  = time.clock() * 1000
print 'Test 2: ', stop_time_2 - start_time_2

def get_time_1():

    start_time_3 = time.clock()
    stop_time_3  = time.clock()
    duration = (stop_time_3 - start_time_3) * 1000
    print 'Test 3: ', duration

def get_time_2():
    start_time_4 = time.clock() * 1000
    stop_time_4  = time.clock() * 1000
    print 'Test 4: ', stop_time_4 - start_time_4

print '\nOK, now loop the methods...\n'

for ix in range(10):
    print
    get_time_1()
    get_time_2()

module_time_stop = time.clock()

print '\nTotal module time: \n', (module_time_stop - module_time_start) * 1000

# THE RESULTS:

Test 1:  0.00363174649292
Test 2:  0.0167619068904

OK, now loop the methods...


Test 3:  0.00810158833036
Test 4:  0.0145269859717

Test 3:  0.006984127871
Test 4:  0.0145269859717

Test 3:  0.00586666741164
Test 4:  0.0145269859717

Test 3:  0.00614603252648
Test 4:  0.0145269859717

Test 3:  0.00614603252648
Test 4:  0.013968255742

Test 3:  0.00586666741164
Test 4:  0.0128507952826

Test 3:  0.00586666741164
Test 4:  0.0136888906272

Test 3:  0.0055873022968
Test 4:  0.0136888906272

Test 3:  0.00642539764132
Test 4:  0.0145269859717

Test 3:  0.0108952394788
Test 4:  0.0145269859717

Total module time: 
2.89142893859



More information about the Python-list mailing list