Advertisement
cookertron

Speed test between HYPOT and X * X + Y * Y

Nov 1st, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. # Looking for a pygame community? fb.com/groups/pygame
  2. # Any skill level can join!
  3.  
  4. import time
  5. import math
  6. import random
  7.  
  8. WIDTH = 1280
  9. HEIGHT = 720
  10.  
  11. x1 = random.randint(0, WIDTH)
  12. y1 = random.randint(0, HEIGHT)
  13.  
  14. x2 = random.randint(0, WIDTH)
  15. y2 = random.randint(0, HEIGHT)
  16.  
  17. x = x1 - x2
  18. y = y1 - y2
  19.  
  20. cycles = 10000000
  21. start = time.time()
  22. for i in xrange(cycles):
  23.     #distance = math.hypot(x, y)
  24.     distance = x * x + y * y
  25. end = time.time()
  26.  
  27.  
  28. duration = end - start
  29.  
  30. print "Duration: {0}".format(duration)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement