-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
45 lines (34 loc) · 1.21 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
longqi 1/Feb/16 20:55
"""
from ctypes import *
import timeit
# import pyximport
# pyximport.install()
# import fibRec_Cython
import fibRec_Cython
# import fibRec_C
CLib = cdll.LoadLibrary("./libfunctions.dylib")
def fibRec_Python(n):
if n < 2:
return n
else:
return fibRec_Python(n - 1) + fibRec_Python(n - 2)
number = 32
# Python 3 Fibonacci
print("Python\t:",
min(timeit.Timer(stmt='x = fibRec_Python(number)',
setup='from __main__ import fibRec_Python, number').repeat(repeat=10,
number=1)))
# Cython Fibonacci
print("Cython\t:",
min(timeit.Timer(stmt='x = fibRec_Cython.fibRec(number)',
setup='from __main__ import fibRec_Cython, number').repeat(repeat=10,
number=1)))
# C Fibonacci
print("C lib\t:",
min(timeit.Timer(stmt='x = CLib.fibRec(number)',
setup='from __main__ import CLib, number').repeat(repeat=10,
number=1)))