fork(3) download
  1. import functools
  2. from scipy import integrate
  3.  
  4. def counted_calls(f):
  5. @functools.wraps(f)
  6. def count_wrapper(*args, **kwargs):
  7. count_wrapper.count += 1
  8. return f(*args, **kwargs)
  9. count_wrapper.count = 0
  10. return count_wrapper
  11.  
  12. def f(x): return x**2
  13.  
  14. wrapped = counted_calls(f)
  15. integrate.quad(wrapped, 0, 1)
  16. print(wrapped.count)
Success #stdin #stdout 0.17s 200832KB
stdin
Standard input is empty
stdout
21