2014-06-18 20:20:34 -04:00
|
|
|
# Function call overhead test
|
|
|
|
# Perform the same trivial operation as calling function, cached in a
|
|
|
|
# local variable. This is commonly known optimization for overly dynamic
|
|
|
|
# languages (the idea is to cut on symbolic look up overhead, as local
|
|
|
|
# variables are accessed by offset, not by name)
|
|
|
|
import bench
|
|
|
|
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2014-06-18 20:20:34 -04:00
|
|
|
def f(x):
|
|
|
|
return x + 1
|
|
|
|
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2014-06-18 20:20:34 -04:00
|
|
|
def test(num):
|
|
|
|
f_ = f
|
|
|
|
for i in iter(range(num)):
|
|
|
|
a = f_(i)
|
|
|
|
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2014-06-18 20:20:34 -04:00
|
|
|
bench.run(test)
|