jedoch wird mir das Ergebniss als hexadezimalzahl ausgegeben, wie kann ich das den ändern?
Die 2 Funktionen sollen verglichen werden.
Hier der Code:
Code: Alles auswählen
#!/usr/bin/python
import math
import time
n=4
o=4
def fib1(n):
start= time.clock()
while n <= 17:
if n <= 1: return 1
return fib1(n-1)+fib1(n-2)
n +=1
ende= time.clock()
zeit1 = ende-start
return zeit1
print fib1
def fib2(o, a=1, b=1):
start= time.clock()
while o <= 40:
if n == 0: return a
elif n == 1: return b
else: return fib2(n-1, b, a+b)
o +=1
ende= time.clock()
zeit2 = ende-start
return zeit2
print fib2
Code: Alles auswählen
danny@danny:~$ python timeclock.py
<function fib1 at 0x7ffc38ce45f0>
<function fib2 at 0x7ffc38ceec08>
will das ganze später noch als plot darstellen sow eit bin ich aber noch nicht...
hab auch den Thread hier gefunden:
http://www.python-forum.de/viewtopic.ph ... w=previous
hilft mir jedoch nicht sonderlich viel weiter
EDIT:
habs jetzt noch so:
Code: Alles auswählen
#!/usr/bin/python
import math
import timeit
def fib1(n):
if n <= 1: return 1
return fib1(n-1)+fib1(n-2)
def fib2(n, a=1, b=1):
if n == 0: return a
elif n == 1: return b
else: return fib2(n-1, b, a+b)
t1 = timeit.Timer("fib1(4)", "from __main__ import fib1")
t2 = timeit.Timer("fib2(4)", "from __main__ import fib2")
print t1.timeit()
print t2.timeit()