Re: What is the "functional" way of doing this?
- From: Ricardo Aráoz <ricaraoz@xxxxxxxxx>
- Date: Tue, 31 Jul 2007 09:01:42 -0300
Considering I am a beginner I did a little test. Funny results too. The
function I proposed (lists1.py) took 11.4529998302 seconds, while the
other one (lists2.py) took 16.1410000324 seconds, thats about 40% more.
They were run in IDLE from their own windows (F5).
Of course my little test may me wrong (just started with this language),
in which case I would appreciate any corrections, or comments.
------------------------------------------------
lists1.py :
def f(n):
if n > 0:
return ([n%26] + f(n/26))
else:
return []
import time
start = time.time()
for x in range(1,1000000):
f(2100000000)
end = time.time()
print end - start
-----------------------------------------------
lists2.py :
def f(n):
def mseq(n):
while n > 0:
n,a = divmod(n, 26)
yield a
return list(mseq(n))
import time
start = time.time()
for x in range(1,1000000):
f(2100000000)
end = time.time()
print end - start
------------------------------------------------
.
- Follow-Ups:
- Re: What is the "functional" way of doing this?
- From: Steven D'Aprano
- Re: What is the "functional" way of doing this?
- References:
- What is the "functional" way of doing this?
- From: beginner
- Re: What is the "functional" way of doing this?
- From: attn.steven.kuo@xxxxxxxxx
- Re: What is the "functional" way of doing this?
- From: Paul Rubin
- Re: What is the "functional" way of doing this?
- From: attn.steven.kuo@xxxxxxxxx
- What is the "functional" way of doing this?
- Prev by Date: Re: interaction of 'with' and 'yield'
- Next by Date: Re: simple string backspace question
- Previous by thread: Re: What is the "functional" way of doing this?
- Next by thread: Re: What is the "functional" way of doing this?
- Index(es):
Relevant Pages
|