Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- coords = [(math.sin(x*math.pi/500), math.cos(x*math.pi/500)) for x in range(10000000)]
- @profile
- def f():
- thetas = [math.atan2(coords[0][1], coords[0][0])]
- prev = thetas[0]
- for index in range(1, len(coords)):
- coord = coords[index]
- theta = math.atan2(coord[1], coord[0]) + (prev // (2*math.pi)) * (2 * math.pi)
- while theta - prev > math.pi:
- theta -= 2*math.pi
- while prev - theta > math.pi:
- theta += 2*math.pi
- assert abs(theta - prev) < math.pi/2
- thetas.append(theta)
- prev = theta
- f()
- ##Timer unit: 4.10528e-07 s
- ##
- ##File: <nope>
- ##Function: f at line 5
- ##Total time: 114.679 s
- ##
- ##Line # Hits Time Per Hit % Time Line Contents
- ##==============================================================
- ## 5 @profile
- ## 6 def f():
- ## 7 1 37 37.0 0.0 thetas = [math.atan2(coords[0][1], coords[0][0])]
- ## 8 1 3 3.0 0.0 prev = thetas[0]
- ## 9 10000000 19992061 2.0 7.2 for index in range(1, len(coords)):
- ## 10 9999999 24776580 2.5 8.9 coord = coords[index]
- ## 11 9999999 61555671 6.2 22.0 theta = math.atan2(coord[1], coord[0]) + (prev // (2*math.pi)) * (2 * math.pi)
- ## 12 9999999 32881846 3.3 11.8 while theta - prev > math.pi:
- ## 13 theta -= 2*math.pi
- ## 14 14990820 40634922 2.7 14.5 while prev - theta > math.pi:
- ## 15 4990821 15307461 3.1 5.5 theta += 2*math.pi
- ## 16 9999999 36460032 3.6 13.1 assert abs(theta - prev) < math.pi/2
- ## 17 9999999 27592582 2.8 9.9 thetas.append(theta)
- ## 18 9999999 20143660 2.0 7.2 prev = theta
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement