I've been trying this Python iterative code to get the Fibonacci sequence on Windows and Linux. The problem is that this code takes much longer to execute on Windows and I don't know why. Is it due to the memory management of Windows? Both OS use Python 3.
def fib(n):
old = 0
new = 1
temp = 0
for i in range(1,n):
temp = new
new = new + old
old = temp
return new
def main():
a = 10000
for i in range(1,51):
start_time = time.time()
fib(a)
elapsed_time = time.time() - start_time
print("%.10f" % elapsed_time)
a = a+10000
The time is measured in seconds.
Time graph:
Thank you.
UPDATE: cProfile on both OS
The "percall" time seems to be huge on Windows compared to Linux.