Advertisement
Guest User

Untitled

a guest
Feb 16th, 2015
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.01 KB | None | 0 0
  1. import math
  2.  
  3. coords = [(math.sin(x*math.pi/500), math.cos(x*math.pi/500)) for x in range(10000000)]
  4.  
  5. @profile
  6. def f():
  7.     thetas = [math.atan2(coords[0][1], coords[0][0])]
  8.     prev = thetas[0]
  9.     for index in range(1, len(coords)):
  10.         coord = coords[index]
  11.         theta = math.atan2(coord[1], coord[0]) + (prev // (2*math.pi)) * (2 * math.pi)
  12.         while theta - prev > math.pi:
  13.             theta -= 2*math.pi
  14.         while prev - theta > math.pi:
  15.             theta += 2*math.pi
  16.         assert abs(theta - prev) < math.pi/2
  17.         thetas.append(theta)
  18.         prev = theta
  19.  
  20. f()
  21.  
  22. ##Timer unit: 4.10528e-07 s
  23. ##
  24. ##File: <nope>
  25. ##Function: f at line 5
  26. ##Total time: 114.679 s
  27. ##
  28. ##Line #      Hits         Time  Per Hit   % Time  Line Contents
  29. ##==============================================================
  30. ##     5                                           @profile
  31. ##     6                                           def f():
  32. ##     7         1           37     37.0      0.0      thetas = [math.atan2(coords[0][1], coords[0][0])]
  33. ##     8         1            3      3.0      0.0      prev = thetas[0]
  34. ##     9  10000000     19992061      2.0      7.2      for index in range(1, len(coords)):
  35. ##    10   9999999     24776580      2.5      8.9          coord = coords[index]
  36. ##    11   9999999     61555671      6.2     22.0          theta = math.atan2(coord[1], coord[0]) + (prev // (2*math.pi)) * (2 * math.pi)
  37. ##    12   9999999     32881846      3.3     11.8          while theta - prev > math.pi:
  38. ##    13                                                       theta -= 2*math.pi
  39. ##    14  14990820     40634922      2.7     14.5          while prev - theta > math.pi:
  40. ##    15   4990821     15307461      3.1      5.5              theta += 2*math.pi
  41. ##    16   9999999     36460032      3.6     13.1          assert abs(theta - prev) < math.pi/2
  42. ##    17   9999999     27592582      2.8      9.9          thetas.append(theta)
  43. ##    18   9999999     20143660      2.0      7.2          prev = theta
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement