Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- #
- # uses kcachegrind, a visualization tool
- # uses pyprof2calltree
- # factorial and two functions use taylor_exp
- # and taylor_sin. They represent the polynomial
- # coeffients of the Taylor approximations of
- # exp(x) and sin(x):
- def factorial(n):
- if n == 0:
- return 1.0
- else:
- return float(n) * factorial(n - 1)
- def taylor_exp(n):
- return [1.0 / factorial(i) for i in range(n)]
- def talyor_sin(n):
- res = []
- for i in range(n):
- if i % 2 == 1:
- res.append((-1) ** ((i - 1) / 2) / float(factorial(i)))
- else:
- res.append(0.0)
- return res
- def benchmark():
- taylor_exp(500)
- taylor_sin(500)
- if __name__ == '__main__':
- benchmark()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement