From: Denis K. <de...@ya...> - 2004-10-05 18:57:13
|
Hi all, I'm having trouble with this piece of code. It seems like __call__ version is not being handled correctly. import psyco import time import array ONEOVERTWELVE = 1.0 / 12.0 CACHEINITIALIZER = [0.0] * 100 CACHEBOOLINITIALIZER = [0] * 100 class Foobar_TYPE: def __init__(self): self.cache = array.array('d', CACHEINITIALIZER) self.cachevalid = array.array('b', CACHEBOOLINITIALIZER) def __call__(self, m): if self.cachevalid[m]: return self.cache[m] if m <= 1: self.cachevalid[1] = 1 self.cache[1] = 1 return self.cache[1] else: self.cachevalid[m] = 1 self.cache[m] = pow((1.0 - foo[m]), ONEOVERTWELVE) * Foobar(m-1) return self.cache[m] def benchmark(): start = time.clock() for i in xrange(0, 1000000): Foobar(99) print "in %.2f seconds" % (time.clock() - start) def benchmark1(): start = time.clock() for i in xrange(0, 1000000): Foobar.__call__(99) print "in %.2f seconds" % (time.clock() - start) if __name__ == '__main__': global f global Foobar foo = [0.0005] * 100 Foobar = Foobar_TYPE() psyco.bind(benchmark1, 1000) psyco.bind(benchmark, 1000) benchmark() benchmark1() in 1.09 seconds in 0.28 seconds benchmark1 runs over 4.5 times faster! Any ideas. -Denis __________________________________ Do you Yahoo!? New and Improved Yahoo! Mail - Send 10MB messages! http://promotions.yahoo.com/new_mail |
From: Tim H. <tim...@co...> - 2004-10-05 19:43:02
|
Denis Kenzior wrote: >Hi all, > >I'm having trouble with this piece of code. It seems >like __call__ version is not being handled correctly. > > By "not correctly" it seems you mean that it's not being sped up much, not that it's producing an incorrect result. Is that correct? If the former, it's not that big of a deal: there are many constructs that aren't sped up much by psyco and this is probably one of them. Of course, if you're lucky Armin will see your message and decide to speed this up, but I have a feeling that code involved is convoluted. On the other hand, if it's producing incorrect results, that would be a big deal and I'm sure a bug report would be appreciated. >benchmark1 runs over 4.5 times faster! > >Any ideas. > > Try inheriting from object. This speeds up both cases. Of course the discrepancy ends up even larger then: here benchmark1 ends up running 13 times faster than benchmark. -tim |
From: Denis K. <de...@ya...> - 2004-10-05 20:25:27
|
Sorry, Yes the output produced is correct. That is not in question, however the speedup is a large discrepancy. I know the code is convoluted, however if possible we would like to use the benchmark() calling convention. This is mainly so our users, who are not programmers can better understand what's going on. Just wondering if its something which can be easily fixed, otherwise no big deal. Btw, Psyco rocks! :) -Denis --- Tim Hochberg <tim...@co...> wrote: > Denis Kenzior wrote: > > >Hi all, > > > >I'm having trouble with this piece of code. It > seems > >like __call__ version is not being handled > correctly. > > > > > By "not correctly" it seems you mean that it's not > being sped up much, > not that it's producing an incorrect result. Is that > correct? If the > former, it's not that big of a deal: there are many > constructs that > aren't sped up much by psyco and this is probably > one of them. Of > course, if you're lucky Armin will see your message > and decide to speed > this up, but I have a feeling that code involved is > convoluted. > > On the other hand, if it's producing incorrect > results, that would be a > big deal and I'm sure a bug report would be > appreciated. > > > > >benchmark1 runs over 4.5 times faster! > > > >Any ideas. > > > > > Try inheriting from object. This speeds up both > cases. Of course the > discrepancy ends up even larger then: here > benchmark1 ends up running 13 > times faster than benchmark. > > -tim > > > > ------------------------------------------------------- > This SF.net email is sponsored by: IT Product Guide > on ITManagersJournal > Use IT products in your business? Tell us what you > think of them. Give us > Your Opinions, Get Free ThinkGeek Gift Certificates! > Click to find out more > http://productguide.itmanagersjournal.com/guidepromo.tmpl > _______________________________________________ > Psyco-devel mailing list > Psy...@li... > https://lists.sourceforge.net/lists/listinfo/psyco-devel > __________________________________ Do you Yahoo!? New and Improved Yahoo! Mail - 100MB free storage! http://promotions.yahoo.com/new_mail |