benchmark
Collapse
This topic is closed.
X
X
-
JackTags: None -
bearophileHUGS@lycos.com
Re: benchmark
On Aug 7, 2:05 am, "Jack" <nos...@invalid .comwrote:That Python code is bad, it contains range() instead of xrange, theI know one benchmark doesn't mean much but it's still disappointing to see
Python as one of the slowest languages in the test:
>
http://blog.dhananjaynene.com/2008/0...rison-c-java-p...
big loop is in the main code instead of inside a function, uses ==
None, etc. That person can try this (with Psyco), I have changed very
little, the code is essentially the same:
import time, psyco
from psyco.classes import __metaclass__
class Person:
def __init__(self, count):
self.count = count
self.prev = None
self.next = None
def shout(self, shout, deadif):
if shout < deadif:
return shout + 1
self.prev.next = self.next
self.next.prev = self.prev
return 1
class Chain:
def __init__(self, size):
self.first = None
last = None
for i in xrange(size):
current = Person(i)
if self.first is None:
self.first = current
if last is not None:
last.next = current
current.prev = last
last = current
self.first.prev = last
last.next = self.first
def kill(self, nth):
current = self.first
shout = 1
while current.next != current:
shout = current.shout(s hout, nth)
current = current.next
self.first = current
return current
def main():
ITER = 100000
start = time.time()
for i in xrange(ITER):
chain = Chain(40)
chain.kill(3)
end = time.time()
print 'Time per iteration = %s microseconds ' % ((end - start) *
1000000 / ITER)
psyco.full()
main()
us = microseconds
On my PC (that seems similar to his one) this version needs about 38.9
us/iter instead of 189.
On my PC the Java version takes 1.17 us, while the C++ version (with
MinGW 4.2.1) takes 9.8 us.
A raw D translation needs 14.34 us, while a cleaned up (that uses
structs, no getters/setters) needs 4.67 us.
I don't know why my C++ is so much slow (doing the same things to the C
++ version doesn't change its running time much).
Bye,
bearophile
Comment
-
Stefan Behnel
Re: benchmark
Jack wrote:Just ignore that. If the code had been designed for Python from the start, itI know one benchmark doesn't mean much but it's still disappointing to see
Python as one of the slowest languages in the test:
>
http://blog.dhananjaynene.com/2008/0...-jruby-groovy/
would have performed a lot better.
Currently it looks like syntax-adapted Java code to me.
Stefan
Comment
-
Steven D'Aprano
Re: benchmark
On Thu, 07 Aug 2008 07:49:45 +0200, Stefan Behnel wrote:
python-ruby-jython-jruby-groovy/Jack wrote:>I know one benchmark doesn't mean much but it's still disappointing to
>see Python as one of the slowest languages in the test:
>>
>http://blog.dhananjaynene.com/2008/0...arison-c-java->
Just ignore that. If the code had been designed for Python from the
start, it would have performed a lot better.
I recommend folks copy and paste his code into an interactive session,
and watch the thousands of <__main__.Perso n object at 0xb7f18e2cthat
flash onto the screen. You want to know why it's so slow? That's part of
the reason.
Doing so on my computer gives a final result of:
"Time per iteration = 502.890818119 microseconds"
When I make a single, two character modification to the program
(inserting "t=" at the beginning of the line "chain.kill(3)" ), I get this
instead:
"Time per iteration = 391.469910145 microseconds"
In other words, about 20% of the time he measures is the time taken to
print junk to the screen.
--
Steven
Comment
-
jlist
Re: benchmark
I think what makes more sense is to compare the code one most
typically writes. In my case, I always use range() and never use psyco.
But I guess for most of my work with Python performance hasn't been
a issue. I haven't got to write any large systems with Python yet, where
performance starts to matter.
That Python code is bad, it contains range() instead of xrange, the
big loop is in the main code instead of inside a function, uses ==
None, etc. That person can try this (with Psyco), I have changed very
little, the code is essentially the same:
Comment
-
alex23
Re: benchmark
Steven D'Aprano wrote:Which makes his claim that "all the console outputs have been removedIn other words, about 20% of the time he measures is the time taken to
print junk to the screen.
so that the benchmarking activity is not interfered with by the IO
overheads" somewhat confusing...he didn't notice the output? Wrote it
off as a weird Python side-effect?
I find his reluctance to entertain more idiomatic implementations
particularly telling. It's seems he's less interested in actual
performance comparisons and more into showing that writing static lang
style code in dynamic langs is bad, which isn't really anything new to
anyone anywhere, I would've thought.
All up, this reminds me of last years benchmarking fiasco that
demonstrated Storm's ORM handling being -incredibly-faster than
SQLAlchemy's SQL expression handling, something that just didn't seem
to be born out by user experience. Eventually, Mike Beyer reverse
engineered the benchmarks to discover that, surprise surprise, the
tests -weren't equal-; in one test SQLA was issuing a commit per
insert, while Storm was performing -no commits whatsoever-.
Benchmarks, IMO, are like statistics. You can tweak them to prove
pretty much any position you already take.
Comment
-
Steven D'Aprano
Re: benchmark
On Thu, 07 Aug 2008 00:44:14 -0700, alex23 wrote:
Wait... I've just remembered, and a quick test confirms... Python onlySteven D'Aprano wrote:>>In other words, about 20% of the time he measures is the time taken to
>print junk to the screen.
Which makes his claim that "all the console outputs have been removed so
that the benchmarking activity is not interfered with by the IO
overheads" somewhat confusing...he didn't notice the output? Wrote it
off as a weird Python side-effect?
prints bare objects if you are running in a interactive shell. Otherwise
output of bare objects is suppressed unless you explicitly call print.
Okay, I guess he is forgiven. False alarm, my bad.
--
Steven
Comment
-
Angel Gutierrez
Re: benchmark
Steven D'Aprano wrote:
Well.. there must be somthing because this is what I got in a normal scriptOn Thu, 07 Aug 2008 00:44:14 -0700, alex23 wrote:
>>>Steven D'Aprano wrote:>>>>In other words, about 20% of the time he measures is the time taken to
>>print junk to the screen.
>Which makes his claim that "all the console outputs have been removed so
>that the benchmarking activity is not interfered with by the IO
>overheads" somewhat confusing...he didn't notice the output? Wrote it
>off as a weird Python side-effect?
Wait... I've just remembered, and a quick test confirms... Python only
prints bare objects if you are running in a interactive shell. Otherwise
output of bare objects is suppressed unless you explicitly call print.
>
Okay, I guess he is forgiven. False alarm, my bad.
>
>
execution:
[angel@jaulat test]$ python iter.py
Time per iteration = 357.467989922 microseconds
[angel@jaulat test]$ vim iter.py
[angel@jaulat test]$ python iter2.py
Time per iteration = 320.306909084 microseconds
[angel@jaulat test]$ vim iter2.py
[angel@jaulat test]$ python iter2.py
Time per iteration = 312.917997837 microseconds
iter.py - Original script
iter2.py - xrange instead of range
iter2.py (2nd) - 't=' added
--
Angel
Comment
-
M8R-n7vorv@mailinator.com
Re: benchmark
On Aug 7, 6:38 am, bearophileH...@ lycos.com wrote:Yes, this was pointed out in the comments. I had updated the code toOn Aug 7, 2:05 am, "Jack" <nos...@invalid .comwrote:
>>>I know one benchmark doesn't mean much but it's still disappointing to see
Python as one of the slowest languages in the test:
That Python code is bad, it contains range() instead of xrange, the
big loop is in the main code instead of inside a function, uses ==
None, etc. That person can try this (with Psyco), I have changed very
little, the code is essentially the same:
>
use
xrange and is and is not instead of range, == and !=, which is how
the
benchmark got updated to 192 microseconds. Moving the main loop into
a main function resulted in no discernible difference.
Testing with psyco resulted in a time of 33 microseconds per
iteration.
Wonder what optimisation level you are using. I to the best of myOn my PC the Java version takes 1.17 us, while the C++ version (with
MinGW 4.2.1) takes 9.8 us.
A raw D translation needs 14.34 us, while a cleaned up (that uses
structs, no getters/setters) needs 4.67 us.
I don't know why my C++ is so much slow (doing the same things to the C
++ version doesn't change its running time much).
>
Bye,
bearophile
recollection used -O3
Cheers,
Dhananjay
ReddyBook offers the best online cricket betting experience in India. Get your ReddyBook ID and bet on live cricket markets with us.
Comment
-
Bruno Desthuilliers
Re: benchmark
Steven D'Aprano a écrit :This only happens when run in an interactive session.On Thu, 07 Aug 2008 07:49:45 +0200, Stefan Behnel wrote:
>python-ruby-jython-jruby-groovy/>Jack wrote:>>I know one benchmark doesn't mean much but it's still disappointing to
>>see Python as one of the slowest languages in the test:
>>>
>>http://blog.dhananjaynene.com/2008/0...arison-c-java->>Just ignore that. If the code had been designed for Python from the
>start, it would have performed a lot better.
>
I recommend folks copy and paste his code into an interactive session,
and watch the thousands of <__main__.Perso n object at 0xb7f18e2cthat
flash onto the screen. You want to know why it's so slow? That's part of
the reason.
Comment
-
M8R-n7vorv@mailinator.com
Re: benchmark
On Aug 7, 12:44 pm, alex23 <wuwe...@gmail. comwrote:Gee, I really hope I am a little more capable than writing it off. AndSteven D'Aprano wrote:>In other words, about 20% of the time he measures is the time taken to
print junk to the screen.
Which makes his claim that "all the console outputs have been removed
so that the benchmarking activity is not interfered with by the IO
overheads" somewhat confusing...he didn't notice the output? Wrote it
off as a weird Python side-effect?
to
answer your question bluntly no I did not notice the output because
there
wasn't any. Run a python program as "python filename.py" instead
of using the interactive console, and you will not get any output
except
exceptions or anything that your code explicitly spews out.I am reluctant to entertain more idiomatic implementations was in the>
I find his reluctance to entertain more idiomatic implementations
particularly telling. It's seems he's less interested in actual
performance comparisons and more into showing that writing static lang
style code in dynamic langs is bad, which isn't really anything new to
anyone anywhere, I would've thought.
context of what to me made sense as a part of the exercise. I have
fully
and in great detail explained the rationale in the post itself.
How's this position of mine for starters :>
Benchmarks, IMO, are like statistics. You can tweak them to prove
pretty much any position you already take.
? And if you are not sure, you could browse this as well :
Really how silly can it be when you suggest someone is taking a
position and tweaking the benchmarks to prove a point, when I am
actually quite enthusiastic about python, really like coding using it,
and it was disappointing to me just like to jack who started off this
thread that python did not do so well. In fact I would argue that it
wasn't entirely easy to actually publish the findings given the fact
that these would not have been the findings I would've been wished
for.
Cheers,
Dhananjay
ReddyBook offers the best online cricket betting experience in India. Get your ReddyBook ID and bet on live cricket markets with us.
Comment
-
bearophileHUGS@lycos.com
Re: benchmark
jlist:If you don't use Python 3 and your cycles can be long, then I suggestI think what makes more sense is to compare the code one most
typically writes. In my case, I always use range() and never use psyco.
you to start using xrange a lot :-) (If you use Psyco you don't need
xrange).
M8R-n7v...:For this program I have used the best (simple) combination of flags IWonder what optimisation level you are using. I to the best of my
recollection used -O3
have found by try & errors:
-O3 -s -fomit-frame-pointer
I'll try adding a freelist, to see (and probably show you) the
results. The HotSpot speeds up this code first of all because its GC
is much better than the current one used by D, because it optimizes
away the getters/setters that D is unable to do, and probably manages
the methods two classes as static ones (while D manages all of them as
virtual).
Bye,
bearophile
Comment
-
Bruno Desthuilliers
Re: benchmark
Stefan Behnel a écrit :Yeps, sure. I don't have time for this now, but I think I would haveJack wrote:>>I know one benchmark doesn't mean much but it's still disappointing to see
>Python as one of the slowest languages in the test:
>>
>http://blog.dhananjaynene.com/2008/0...-jruby-groovy/
Just ignore that. If the code had been designed for Python from the start, it
would have performed a lot better.
>
Currently it looks like syntax-adapted Java code to me.
choose an itertool based solution here instead of that hand-made linked
list.
StefanComment
-
M8R-n7vorv@mailinator.com
Re: benchmark
On Aug 7, 5:05 am, "Jack" <nos...@invalid .comwrote:I was actually disappointed myself with the results from a pythonI know one benchmark doesn't mean much but it's still disappointing to see
Python as one of the slowest languages in the test:
>
http://blog.dhananjaynene.com/2008/0...rison-c-java-p...
perspective. One thing I did notice was that both ruby and groovy have
substantially improved performance in their new versions. There is a
likelihood that maybe this particular code is not best suited for
pythonic idioms, but the same would've been the case I guess for ruby,
jruby and groovy, yet they performed really well. While I am a
relative newcomer to the python world, from what I have seen, ruby /
jruby and groovy are all making substantial improvements in their
performance (If this post did not include the newer versions of these
languages, python would've been on top of all of them) but I haven't
seen any evidence of the same in upcoming versions of python.
Having said that the same code with psyco works really fast (and beats
all the other dynamic languages v. handsomely). But I did not include
it in the comparisons because psyco is really not a part of core
feature set of python and I was unclear of the implications thereof.
Is there any reason why the psyco is not a part of the core python
feature set ? Is there a particular reason it is better to be kept as
a separate extension ? Are there any implications of using psyco ?
Cheers,
Dhananjay
ReddyBook offers the best online cricket betting experience in India. Get your ReddyBook ID and bet on live cricket markets with us.
Comment
Comment