JGuizard
6/27/2016 - 9:30 AM

System benchmarks in python.

System benchmarks in python.

from timeit import default_timer as timer

def F(n):
    if n == 0: return 0
    elif n == 1: return 1
    else: return F(n-1)+F(n-2)
    
def benchmark():

    for i in range(1,5):
        start=timer()
        F(i*10)
        end=timer()
        print "Fibonacci "+str(i*10)+": "+str((end-start))
  
 
benchmark()
from timeit import default_timer as timer

def F(n):
    if n == 0: return 0
    elif n == 1: return 1
    else: return F(n-1)+F(n-2)
    
def benchmark(n):
	start=timer()
	F(n)
	end=timer()
	print(end-start)
  
 
n=input("Insert fibonacci n value: ")
benchmark(n)
    
from benchmarker import Benchmarker

## specify number of loop
with Benchmarker(10, width=20) as bench:
    

    def F(n):
        if n == 0: return 0
        elif n == 1: return 1
        else: return F(n-1)+F(n-2)


    @bench(None) 
    def _(bm):
        for i in bm:
            pass

    @bench("Fibonacci 10")
    def _(bm):
        for i in bm:
            F(10)

    @bench("Fibonacci 20")
    def _(bm):
        for i in bm:
            F(20)

    @bench("Fibonacci 30")
    def _(bm):
        for i in bm:
            F(30)