Re: [BangPypers] python speed comparison

2010-08-10 Thread Dhananjay Nene
On Mon, Aug 9, 2010 at 3:59 PM, Emil Chacko wrote: > This implementation is really good.It's really fast compared to the initial > one I posted but i didn't understand much about this memoize.I asked one of > my friend he told it's python decorators.Can anyone please explain what the > function m

Re: [BangPypers] python speed comparison

2010-08-09 Thread Emil Chacko
This implementation is really good.It's really fast compared to the initial one I posted but i didn't understand much about this memoize.I asked one of my friend he told it's python decorators.Can anyone please explain what the function memoize does. > > > Readability counts. Here is my attempt.

Re: [BangPypers] python speed comparison

2010-08-08 Thread Anand Balachandran Pillai
On Fri, Aug 6, 2010 at 8:56 PM, Anand Chitipothu wrote: > Readability counts. Here is my attempt. > > def memoize(f): >cache = {} >def g(a): >if a not in cache: >cache[a] = f(a) >return cache[a] >return g > > @memoize > def solve(n): >if n == 1: >

Re: [BangPypers] python speed comparison

2010-08-06 Thread Anand Chitipothu
Readability counts. Here is my attempt. def memoize(f): cache = {} def g(a): if a not in cache: cache[a] = f(a) return cache[a] return g @memoize def solve(n): if n == 1: return 1 elif n%2 == 0: return 1 + solve(n/2) else:

Re: [BangPypers] python speed comparison

2010-08-06 Thread Abhishek Mishra
> > > > Your python code as is clocked about 72 seconds on my notebook. The > following came in at about 4.6 seconds (just has a small trick of reusing > earlier results) > > import time > start =time.time() > longest = None > longest_elements = 0 > solved = {} > for val in xrange(1,100) : >

Re: [BangPypers] python speed comparison

2010-08-05 Thread Anand Balachandran Pillai
On Fri, Aug 6, 2010 at 3:00 AM, Dhananjay Nene wrote: > On Fri, Jul 23, 2010 at 1:26 PM, Emil Chacko wrote: > > > Below given is solution to a puzzle( > > http://projecteuler.net/index.php?section=problems&id=14) in python and > c > > > > Python: > > > > import time > > startT=time.time() > > max

Re: [BangPypers] python speed comparison

2010-08-05 Thread Dhananjay Nene
On Fri, Jul 23, 2010 at 1:26 PM, Emil Chacko wrote: > Below given is solution to a puzzle( > http://projecteuler.net/index.php?section=problems&id=14) in python and c > > Python: > > import time > startT=time.time() > maxlen=0 > longest=0 > for i in xrange(1,100): > last=i > cnt=0 > while(

Re: [BangPypers] python speed comparison

2010-07-28 Thread Gopalakrishnan Subramani
IronPython (on .NET) and Jython (on Java) capable to use the multi core processors in your PC and they works faster than the CPython. Beware that not all the python packages shall be working with IronPython or Jython. Regards, Krish, http://www.stacked.in ___

Re: [BangPypers] python speed comparison

2010-07-23 Thread Venkatraman S
Try "extending" with python. -V- ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers

Re: [BangPypers] python speed comparison

2010-07-23 Thread Shashwat Anand
On Fri, Jul 23, 2010 at 1:51 PM, Baishampayan Ghose wrote: > Emil, > > > Below given is solution to a puzzle( > > http://projecteuler.net/index.php?section=problems&id=14) in python and > c > > > > Python: > > > > import time > > startT=time.time() > > maxlen=0 > > longest=0 > > for i in xrange(1,

Re: [BangPypers] python speed comparison

2010-07-23 Thread Shashwat Anand
BTW the problem is known as 3n+1 problem and you can find it in ACM archives too. http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=36 ___ BangPypers mailing list BangPypers@python.org http://mail.p

Re: [BangPypers] python speed comparison

2010-07-23 Thread Baishampayan Ghose
Emil, > Below given is solution to a puzzle( > http://projecteuler.net/index.php?section=problems&id=14) in python and c > > Python: > > import time > startT=time.time() > maxlen=0 > longest=0 > for i in xrange(1,100): >  last=i >  cnt=0 >  while(last <> 1): >  cnt=cnt+1 >  if(last%2==0): >  

[BangPypers] python speed comparison

2010-07-23 Thread Emil Chacko
Below given is solution to a puzzle( http://projecteuler.net/index.php?section=problems&id=14) in python and c Python: import time startT=time.time() maxlen=0 longest=0 for i in xrange(1,100): last=i cnt=0 while(last <> 1): cnt=cnt+1 if(last%2==0): last=last/2 else: last=3*last