Effectuer un calcul exponentiel rapidement
cpmoptimize.py
# -*- coding: utf-8 -*-
from benchit import BenchIt
b = BenchIt()
def fib(n):
a = 0
b = 1
for i in xrange(n):
a, b = b, a + b
return a
result = fib(10 ** 6)
b.mark("not use cpmoptimize")
from cpmoptimize import cpmoptimize
@cpmoptimize()
def fib(n):
a = 0
b = 1
for i in xrange(n):
a, b = b, a + b
return a
result = fib(10 ** 6)
b.mark("use cpmoptimize")
b.display()
output.text
+---------------------+----------+------+-------+----------+----------+---------+
| Marker | Method | Line | Loops | Avg Time | Runtime | Percent |
+---------------------+----------+------+-------+----------+----------+---------+
| not use cpmoptimize | <module> | 16 | 1 | 28.56600 | 28.56600 | 96.95 |
| use cpmoptimize | <module> | 30 | 1 | 0.89900 | 0.89900 | 3.05 |
+---------------------+----------+------+-------+----------+----------+---------+
Total runtime: 29.47
pypi github Aim python library master (27) benchit
Recommended Posts