performance difference between OSx and Windows

Brian bnblazer at gmail.com
Sun May 21 18:24:31 EDT 2006


I have been a Mac and linux guy since 1998 and except for a handful of
times, have not touched a MS box since then.  This changes a few days
ago when I needed to get a MS box for another project.  This leads me
to my question...

A while ago, I borrowed a python script from someone's blog that showed
some interesting profiling schemes.  I made some modifications to it,
ran it and until I got this new machine forgot about it.  Just for
kicks I ran it again on both boxes to see what the differences were.
To say I was surprised is an understatement.  Here is the code:

#!/usr/bin/env python

import time

elasped = 0

def slowS():
    t1 = time.clock()
    slow_str=''
    for i in range(100000):
        slow_str = slow_str + str(i)
    print 'Slow concatenation finsished in', time.clock() - t1, 'sec.'

def fastS():
    t2 = time.clock()
    fast_str = []
    for i in range(100000):
        fast_str.append(str(i))
    fast_str = ''.join(fast_str)
    print 'fast concatenation finished in', time.clock() - t2, 'sec.'

#slowS()
#fastS()

if __name__ == '__main__':
    import hotshot
    from hotshot import stats
    prof = hotshot.Profile("Concant_Stats")
    prof.runcall(slowS)
    prof.runcall(fastS)
    prof.close()
    s = stats.load("Concant_Stats")
    s.sort_stats("time").print_stats()

On my Quad G5 Mac with 4g of memory I get this result...
Slow concatenation finsished in 51.05 sec.
fast concatenation finished in 0.63 sec.
         15 function calls in 51.036 CPU seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1   51.033   51.033   51.033   51.033
/Users/brian/Desktop/strTest.py:7(slowS)
        1    0.003    0.003    0.003    0.003
/Users/brian/Desktop/strTest.py:14(fastS)
       12    0.000    0.000    0.000    0.000
/Applications/Komodo.app/Contents/SharedSupport/dbgp/bin/pydbgp:83(write)
        1    0.000    0.000    0.000    0.000
/Applications/Komodo.app/Contents/SharedSupport/dbgp/bin/pydbgp:95(__getattr__)
        0    0.000             0.000          profile:0(profiler)

The MS box is an HP with an Athlon 64 X2 Dual with 1g of memory.  Here
are it's results...
Slow concatenation finsished in 23.798 sec
fast concatenation finished in 0.622 sec
         15 function calls in 87.417 CPU seconds
Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1   85.188   85.188   85.188   85.188 c:\documents and
settings\hp_administrator\desktop\strtest.py:5(slowS)
        1    2.228    2.228    2.229    2.229 c:\documents and
settings\hp_administrator\desktop\strtest.py:12(fastS)
	12    0.001    0.000    0.001    0.000 c:\program files\activestate
komodo 3.5\lib\support\dbgp\bin\pydbgp.py:83(write)
	1    0.000    0.000    0.000    0.000 c:\program files\activestate
komodo 3.5\lib\support\dbgp\bin\pydbgp.py:95(__getattr__)
	0    0.000             0.000          profile:0(profiler)

While the CPU speed on the G5 was faster the total execution time was
much quicker on the MS box.  Can anyone give some suggestions as to why
this is?

Thanks,
Brian




More information about the Python-list mailing list