# math-speed-test.py

Sep 29th, 2020
1,177
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #! /usr/bin/env python3
2.
3. import time, math
4.
5. e = 6; e10 = "10^"+str(e); r = int(10.0 ** e)
6. i1 = 5; i2 = 6
7. f1 = 5.2; f2 = 0.7
8. c1 = 1.2 + 3.4j; c2 = 5.6 + 6.7j
9.
10. t1 = time.time()
11. for j in range(0,r):
12.   x = i1
13. ts = time.time() - t1
14. print(e10, "int assignments: ", int(ts * 1000), "ms")
15.
16. t1 = time.time()
17. for j in range(0,r):
18.   x = i1 + i2
19. ts = time.time() - t1
20. print(e10, "int sums: ", int(ts * 1000), "ms")
21.
22. t1 = time.time()
23. for j in range(0,r):
24.   x = f1 + f2
25. ts = time.time() - t1
26. print(e10, "float sums: ", int(ts * 1000), "ms")
27.
28. t1 = time.time()
29. for j in range(0,r):
30.   x = f1 * f2
31. ts = time.time() - t1
32. print(e10, "float products: ", int(ts * 1000), "ms")
33.
34. t1 = time.time()
35. for j in range(0,r):
36.   x = f1 / f2
37. ts = time.time() - t1
38. print(e10, "float divisions: ", int(ts * 1000), "ms")
39.
40. t1 = time.time()
41. for j in range(0,r):
42.   x = math.sqrt(f1)
43. ts = time.time() - t1
44. print(e10, "square roots: ", int(ts * 1000), "ms")
45. t1 = time.time()
46.
47. t1 = time.time()
48. for j in range(0,r):
49.   x = math.sin(f2)
50. ts = time.time() - t1
51. print(e10, "sines: ", int(ts * 1000), "ms")
52. t1 = time.time()
53.
54. t1 = time.time()
55. for j in range(0,1000000):
56.   x = c1 * c2
57. ts = time.time() - t1
58. print(e10, "complex products: ", int(ts * 1000), "ms")
59. t1 = time.time()
60.
61.
RAW Paste Data