Files
graphene/Examples/python-simple/scripts/fibonacci.py
Michał Kowalczyk 6c7ff2d3a6 Migrate and remove test/apps submodule
We decided to merge the sample app integrations submodule back because
working with git submodules turned out to be really painful. The only
blocker for this was the fact, that previously it contained a lot of
binary blobs and copy-pasted sources, but this was cleaned up recently.

Credits: (authors of particular integration examples, extracted from
commits and PR history in https://github.com/oscarlab/graphene-tests)

apache:     Chia-Che Tsai <chiache@tamu.edu>, Dmitrii Kuvaiskii <dmitrii.kuvaiskii@intel.com>
bash:       Chia-Che Tsai <chiache@tamu.edu>, Dmitrii Kuvaiskii <dmitrii.kuvaiskii@intel.com>
blender:    borysp <borysp@invisiblethingslab.com>
busybox:    borysp <borysp@invisiblethingslab.com>
capnproto:  Dmitrii Kuvaiskii <dmitrii.kuvaiskii@intel.com>
curl:       Dmitrii Kuvaiskii <dmitrii.kuvaiskii@intel.com>
gcc:        Thomas Knauth <thomas.knauth@intel.com>
lighttpd:   Chia-Che Tsai <chiache@tamu.edu>, Thomas Knauth <thomas.knauth@intel.com>
lmbench:    Chia-Che Tsai <chiache@tamu.edu>
memcached:  Dmitrii Kuvaiskii <dmitrii.kuvaiskii@intel.com>
nginx:      Dmitrii Kuvaiskii <dmitrii.kuvaiskii@intel.com>
nodejs:     jack.wxz <jack.wxz@alibaba-inc.com>
nodejs-express-server: Eduardo Rodriguez <erodrig@us.ibm.com>
openvino:   Dmitrii Kuvaiskii <dmitrii.kuvaiskii@intel.com>
python-scipy-insecure: Chia-Che Tsai <chiache@tamu.edu>, Dmitrii Kuvaiskii <dmitrii.kuvaiskii@intel.com>
python-simple:         Chia-Che Tsai <chiache@tamu.edu>, Dmitrii Kuvaiskii <dmitrii.kuvaiskii@intel.com>
pytorch:    Thomas Knauth <thomas.knauth@intel.com>
r:          Chia-Che Tsai <chiache@tamu.edu>
redis:      Dmitrii Kuvaiskii <dmitrii.kuvaiskii@intel.com>
tensorflow: Thomas Knauth <thomas.knauth@intel.com>

LTP was moved to LibOS/shim/test/ltp. It was recently rewritten by
Wojtek Porczyk <woju@invisiblethingslab.com>.
2020-03-30 21:10:41 +02:00

55 lines
1.3 KiB
Python

"""
Downloaded from https://code.google.com/p/benchrun/
Fibonacci numbers test benchmark
"""
from benchrun import Benchmark, clock
def fib1(n):
if n < 2:
return n
return fib1(n-1) + fib1(n-2)
def fib2(n):
if n < 2:
return n
a, b = 1, 0
for i in range(n-1):
a, b = a+b, a
return a
class FibonacciBenchmark(Benchmark):
"""Compare time to compute the nth Fibonacci number recursively
(fib1) and iteratively (fib2)."""
# Execute for all combinations of these parameters
parameters = ['version', 'n']
version = ['fib1', 'fib2']
n = range(0, 60, 5)
# Compare timings against this parameter value
reference = ('version', 'fib1')
def run(self, n, version):
f = globals()[version]
# Don't repeat when slow
if version == 'fib1' and n > 10:
# Skip altogether
if n > 30:
return None
t1 = clock()
f(n)
t2 = clock()
return t2-t1
# Need to repeat many times to get accurate timings for small n
else:
t1 = clock()
f(n); f(n); f(n); f(n); f(n); f(n); f(n)
f(n); f(n); f(n); f(n); f(n); f(n); f(n)
t2 = clock()
return (t2 - t1) / 14
if __name__ == '__main__':
FibonacciBenchmark().print_result()