<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Fun with Fibonacci</title>
	<link>http://www.willmcgugan.com/2007/12/12/fun-with-fibonacci/</link>
	<description>Blog of Will McGugan</description>
	<pubDate>Fri, 21 Nov 2008 01:00:09 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
		<item>
		<title>By: Wo kann ich filme downloaden? Danke</title>
		<link>http://www.willmcgugan.com/2007/12/12/fun-with-fibonacci/#comment-28936</link>
		<dc:creator>Wo kann ich filme downloaden? Danke</dc:creator>
		<pubDate>Tue, 01 Jul 2008 11:58:37 +0000</pubDate>
		<guid>http://www.willmcgugan.com/2007/12/12/fun-with-fibonacci/#comment-28936</guid>
		<description>&lt;strong&gt;coole 50 GB Erotik filme downloaden...&lt;/strong&gt;

Wo kann ich filme downloaden?...</description>
		<content:encoded><![CDATA[<p><strong>coole 50 GB Erotik filme downloaden&#8230;</strong></p>
<p>Wo kann ich filme downloaden?&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JeffH</title>
		<link>http://www.willmcgugan.com/2007/12/12/fun-with-fibonacci/#comment-12009</link>
		<dc:creator>JeffH</dc:creator>
		<pubDate>Thu, 13 Dec 2007 13:43:04 +0000</pubDate>
		<guid>http://www.willmcgugan.com/2007/12/12/fun-with-fibonacci/#comment-12009</guid>
		<description>Here is a non-recursive version
&lt;code&gt;
def fib(n):
    prev = -1
    result = 1
    for i in xrange(n+1):
        sum = result + prev
        prev = result
        result = sum
    return result
&lt;/code&gt;
Time elapsed: 0.000813</description>
		<content:encoded><![CDATA[<p>Here is a non-recursive version<br />
<code><br />
def fib(n):<br />
    prev = -1<br />
    result = 1<br />
    for i in xrange(n+1):<br />
        sum = result + prev<br />
        prev = result<br />
        result = sum<br />
    return result<br />
</code><br />
Time elapsed: 0.000813</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eric casteleijn</title>
		<link>http://www.willmcgugan.com/2007/12/12/fun-with-fibonacci/#comment-12000</link>
		<dc:creator>eric casteleijn</dc:creator>
		<pubDate>Thu, 13 Dec 2007 11:22:02 +0000</pubDate>
		<guid>http://www.willmcgugan.com/2007/12/12/fun-with-fibonacci/#comment-12000</guid>
		<description>the first 2 lines of fib should read:

if n == 0 or n == 1:
      return 1</description>
		<content:encoded><![CDATA[<p>the first 2 lines of fib should read:</p>
<p>if n == 0 or n == 1:<br />
      return 1</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob</title>
		<link>http://www.willmcgugan.com/2007/12/12/fun-with-fibonacci/#comment-11996</link>
		<dc:creator>Bob</dc:creator>
		<pubDate>Thu, 13 Dec 2007 10:44:21 +0000</pubDate>
		<guid>http://www.willmcgugan.com/2007/12/12/fun-with-fibonacci/#comment-11996</guid>
		<description>You could try something like this.

import time

def fib(n):    # write Fibonacci series up to n
	"""Print a Fibonacci series up to n."""
	a, b = 0, 1
	for i in range(n):
		#print b
		a, b = b, a+b


startTime = time.clock()		

fib(36)

print 'elapsed time: ', (time.clock() - startTime)</description>
		<content:encoded><![CDATA[<p>You could try something like this.</p>
<p>import time</p>
<p>def fib(n):    # write Fibonacci series up to n<br />
	&#8220;&#8221;"Print a Fibonacci series up to n.&#8221;"&#8221;<br />
	a, b = 0, 1<br />
	for i in range(n):<br />
		#print b<br />
		a, b = b, a+b</p>
<p>startTime = time.clock()		</p>
<p>fib(36)</p>
<p>print &#8216;elapsed time: &#8216;, (time.clock() - startTime)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: filox</title>
		<link>http://www.willmcgugan.com/2007/12/12/fun-with-fibonacci/#comment-11993</link>
		<dc:creator>filox</dc:creator>
		<pubDate>Thu, 13 Dec 2007 09:11:16 +0000</pubDate>
		<guid>http://www.willmcgugan.com/2007/12/12/fun-with-fibonacci/#comment-11993</guid>
		<description>well, this didn't turn out as I'd hoped... for some reason, my python code was mangled :(</description>
		<content:encoded><![CDATA[<p>well, this didn&#8217;t turn out as I&#8217;d hoped&#8230; for some reason, my python code was mangled :(</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: filox</title>
		<link>http://www.willmcgugan.com/2007/12/12/fun-with-fibonacci/#comment-11984</link>
		<dc:creator>filox</dc:creator>
		<pubDate>Thu, 13 Dec 2007 06:57:27 +0000</pubDate>
		<guid>http://www.willmcgugan.com/2007/12/12/fun-with-fibonacci/#comment-11984</guid>
		<description>First, you have an error in the program - it says fib(2) = 1, which is wrong. Your whole sequence is one step behind. and since we're making fast algorithms, here's one even faster (doesn't spend as much memory either):

from time import clock
temp = []
temp.append(1)
temp.append(1)


def fib(n):
    global temp
    if n  %d" % (i, fib(i))
        
    print "Time elapsed: %f" % (clock() - start)</description>
		<content:encoded><![CDATA[<p>First, you have an error in the program - it says fib(2) = 1, which is wrong. Your whole sequence is one step behind. and since we&#8217;re making fast algorithms, here&#8217;s one even faster (doesn&#8217;t spend as much memory either):</p>
<p>from time import clock<br />
temp = []<br />
temp.append(1)<br />
temp.append(1)</p>
<p>def fib(n):<br />
    global temp<br />
    if n  %d&#8221; % (i, fib(i))</p>
<p>    print &#8220;Time elapsed: %f&#8221; % (clock() - start)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JeffH</title>
		<link>http://www.willmcgugan.com/2007/12/12/fun-with-fibonacci/#comment-11971</link>
		<dc:creator>JeffH</dc:creator>
		<pubDate>Thu, 13 Dec 2007 03:20:45 +0000</pubDate>
		<guid>http://www.willmcgugan.com/2007/12/12/fun-with-fibonacci/#comment-11971</guid>
		<description>For comparison, running the code without the memoize decorator I get
Time elapsed: 43.063779

Running Will's memoized version knocks it down to
Time elapsed: 0.001341

Using shedskin, http://mark.dufour.googlepages.com/,  on the non-memoized version runs in
Time elapsed: 0.782071
(remember, I'm not trading memory for speed)

Making a shared library out of fib with shedskin, then importing it and using it results in:
Time elapsed: 1.242797

You really need to check out shedskin -- c++ speeds, python code to maintain</description>
		<content:encoded><![CDATA[<p>For comparison, running the code without the memoize decorator I get<br />
Time elapsed: 43.063779</p>
<p>Running Will&#8217;s memoized version knocks it down to<br />
Time elapsed: 0.001341</p>
<p>Using shedskin, <a href="http://mark.dufour.googlepages.com/," rel="nofollow">http://mark.dufour.googlepages.com/,</a>  on the non-memoized version runs in<br />
Time elapsed: 0.782071<br />
(remember, I&#8217;m not trading memory for speed)</p>
<p>Making a shared library out of fib with shedskin, then importing it and using it results in:<br />
Time elapsed: 1.242797</p>
<p>You really need to check out shedskin &#8212; c++ speeds, python code to maintain</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: billg</title>
		<link>http://www.willmcgugan.com/2007/12/12/fun-with-fibonacci/#comment-11953</link>
		<dc:creator>billg</dc:creator>
		<pubDate>Wed, 12 Dec 2007 21:00:16 +0000</pubDate>
		<guid>http://www.willmcgugan.com/2007/12/12/fun-with-fibonacci/#comment-11953</guid>
		<description>should be even faster with xrange instead of range (unless you're using python3000). of course, you probably won't be able to measure the speedup.</description>
		<content:encoded><![CDATA[<p>should be even faster with xrange instead of range (unless you&#8217;re using python3000). of course, you probably won&#8217;t be able to measure the speedup.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob</title>
		<link>http://www.willmcgugan.com/2007/12/12/fun-with-fibonacci/#comment-11946</link>
		<dc:creator>Bob</dc:creator>
		<pubDate>Wed, 12 Dec 2007 19:06:14 +0000</pubDate>
		<guid>http://www.willmcgugan.com/2007/12/12/fun-with-fibonacci/#comment-11946</guid>
		<description>I just took my own advice that I just gave you.  I ran on WIndows XP with time.time() and I also got 0 seconds.  When I ran using time.clock() I got about 3 milliseconds.</description>
		<content:encoded><![CDATA[<p>I just took my own advice that I just gave you.  I ran on WIndows XP with time.time() and I also got 0 seconds.  When I ran using time.clock() I got about 3 milliseconds.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob</title>
		<link>http://www.willmcgugan.com/2007/12/12/fun-with-fibonacci/#comment-11945</link>
		<dc:creator>Bob</dc:creator>
		<pubDate>Wed, 12 Dec 2007 19:00:28 +0000</pubDate>
		<guid>http://www.willmcgugan.com/2007/12/12/fun-with-fibonacci/#comment-11945</guid>
		<description>You must be using some form of Windows OS.  Python time.time() resolution on Windows XP is around 15 milliseconds.  So you have shown that your algorithm runs in less than about 15 ms on your machine.  Try it again using time.clock().  Python time.clock() on my Windows XP box has about 2 microsecond resolution.</description>
		<content:encoded><![CDATA[<p>You must be using some form of Windows OS.  Python time.time() resolution on Windows XP is around 15 milliseconds.  So you have shown that your algorithm runs in less than about 15 ms on your machine.  Try it again using time.clock().  Python time.clock() on my Windows XP box has about 2 microsecond resolution.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
