[Tutor] Nine Language Performance Round-up: Benchmarking Math & File I/O

Lloyd Kvam pythontutor at venix.com
Fri Jan 9 15:59:01 EST 2004


Your change "breaks" the benchmark because now i increments by 4.  The
skipped values are not used, unlike in the "benchmark".

Unfortunately, the benchmark is simply stress testing pythons garbage
collection capability, not python's arithmetic capabilities.

Christian Wyglendowski wrote:

> I suppose that some of you might have looked at the article mentioned in
> the subject line.  For those who haven't, the reviewer pits Python,
> Python/Psycho, the .NET languages and Java against each other in math
> and file I/O operations.  Here is a link to the article:
> http://www.osnews.com/story.php?news_id=5602
> 
> 
> In the mathematical operations benchmarks, Python does not fair so well
> against the other languages.  I know that these sort of ops aren't
> Python's strong suit, but I was interested to see if there was anyway to
> speed up the stock Python performance in this test.  I only messed with
> the integer math function. 
> 
> Here is a link to the python code used in the benchmark:
> http://www.ocf.berkeley.edu/~cowell/research/benchmark/code/Benchmark.py
> 
> Here is my change to it:
> 
> def intArithmeticNew(intMax):
> 
>     startTime = time.clock()
> 
>     i = 1
>     intResult = 1
>     while i < intMax:
>         intResult = intResult - i
>         
>         intResult = intResult + i
>         
>         intResult = intResult * i
>         
>         intResult = intResult / I
>         ###########
>         i = i + 4 # instead of doing an assignment for each operation,
> we now simply do one assignment for all four
>         ###########
>     stopTime = time.clock()
>     elapsedTime = (stopTime - startTime) * 1000 # convert from secs to
> millisecs.
>     print "Int arithmetic elapsed time:", elapsedTime, "ms with intMax
> of", intMax
>     print " i:", i
>     print " intResult:", intResult
>     return elapsedTime
> 
> Here are the results on my system running the origial code and my
> modified code:
> 
>>>>Benchmark.intArithmetic(1000000000)
> 
> Int arithmetic elapsed time: 293486.648163 ms with intMax of 1000000000
>  i: 1000000001
>  intResult: 1
> 293486.64816338394
> 
>>>>Benchmark.intArithmeticNew(1000000000)
> 
> Int arithmetic elapsed time: 207132.665464 ms with intMax of 1000000000
>  i: 1000000001
>  intResult: 1
> 207132.66546446539
> 
> My change yielded close to a 30% speed increase.  I got the idea to
> reduce the amount of assignments from a comment on the article.  What
> other methods could be used to speed this up?
> 
> Christian
> http://www.dowski.com
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice:	603-653-8139
fax:	801-459-9582




More information about the Tutor mailing list