funcall-3-funcall-local.py 427 B

12345678910111213141516
  1. # Function call overhead test
  2. # Perform the same trivial operation as calling function, cached in a
  3. # local variable. This is commonly known optimization for overly dynamic
  4. # languages (the idea is to cut on symbolic look up overhead, as local
  5. # variables are accessed by offset, not by name)
  6. import bench
  7. def f(x):
  8. return x + 1
  9. def test(num):
  10. f_ = f
  11. for i in iter(range(num)):
  12. a = f_(i)
  13. bench.run(test)