Advertisement
rfmonk

cprof_output_test.py

Mar 28th, 2014
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #
  3. # uses kcachegrind, a visualization tool
  4. # uses pyprof2calltree
  5. # factorial and two functions use taylor_exp
  6. # and taylor_sin. They represent the polynomial
  7. # coeffients of the Taylor approximations of
  8. # exp(x) and sin(x):
  9.  
  10.  
  11. def factorial(n):
  12.     if n == 0:
  13.         return 1.0
  14.     else:
  15.         return float(n) * factorial(n - 1)
  16.  
  17.  
  18. def taylor_exp(n):
  19.     return [1.0 / factorial(i) for i in range(n)]
  20.  
  21.  
  22. def talyor_sin(n):
  23.     res = []
  24.     for i in range(n):
  25.         if i % 2 == 1:
  26.             res.append((-1) ** ((i - 1) / 2) / float(factorial(i)))
  27.         else:
  28.             res.append(0.0)
  29.         return res
  30.  
  31.  
  32. def benchmark():
  33.     taylor_exp(500)
  34.     taylor_sin(500)
  35.  
  36. if __name__ == '__main__':
  37.     benchmark()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement