-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyewacket_tests.py
114 lines (105 loc) · 5.26 KB
/
pyewacket_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import time as _time
import math as _math
import random as _random
import itertools as _itertools
from Pyewacket import *
from MonkeyScope import distribution_timer, timer
def software_seed_test(seed_test_size):
arr1 = [i for i in range(seed_test_size)]
seed(2**32)
shuffle(arr1)
arr2 = [i for i in range(seed_test_size)]
seed(2**32)
shuffle(arr2)
if arr1 == arr2:
print("Software Seed Test Passed")
else:
print("Software Seed Test Failed")
def hardware_seed_test(seed_test_size):
arr3 = [i for i in range(seed_test_size)]
seed(0)
shuffle(arr3)
arr4 = [i for i in range(seed_test_size)]
seed(0)
shuffle(arr4)
if arr3 != arr4:
print("Hardware Seed Test Passed")
else:
print("Hardware Seed Test Failed")
def quick_test():
R = _random.Random()
num_cycles = 10000
print("\nMonkeyScope: Pyewacket\n")
start_test = _time.time()
print("Base Case")
distribution_timer(R._randbelow, 10, num_cycles=num_cycles)
distribution_timer(randbelow, 10, num_cycles=num_cycles)
print("Base Case")
distribution_timer(_random.randint, 1, 10, num_cycles=num_cycles)
distribution_timer(randint, 1, 10, num_cycles=num_cycles)
print("Base Case")
distribution_timer(_random.randrange, 0, 10, 2, num_cycles=num_cycles)
distribution_timer(randrange, 0, 10, 2, num_cycles=num_cycles)
print("Base Case")
distribution_timer(_random.random, post_processor=round, num_cycles=num_cycles)
distribution_timer(random, post_processor=round, num_cycles=num_cycles)
print("Base Case")
distribution_timer(_random.uniform, 0.0, 10.0, post_processor=_math.floor, num_cycles=num_cycles)
distribution_timer(uniform, 0.0, 10.0, post_processor=_math.floor, num_cycles=num_cycles)
print("Base Case")
distribution_timer(_random.expovariate, 1.0, post_processor=_math.floor, num_cycles=num_cycles)
distribution_timer(expovariate, 1.0, post_processor=_math.floor, num_cycles=num_cycles)
print("Base Case")
distribution_timer(_random.gammavariate, 2.0, 1.0, post_processor=round, num_cycles=num_cycles)
distribution_timer(gammavariate, 2.0, 1.0, post_processor=round, num_cycles=num_cycles)
print("Base Case")
distribution_timer(_random.weibullvariate, 1.0, 1.0, post_processor=_math.floor, num_cycles=num_cycles)
distribution_timer(weibullvariate, 1.0, 1.0, post_processor=_math.floor, num_cycles=num_cycles)
print("Base Case")
distribution_timer(_random.betavariate, 3.0, 3.0, post_processor=round, num_cycles=num_cycles)
distribution_timer(betavariate, 3.0, 3.0, post_processor=round, num_cycles=num_cycles)
print("Base Case")
distribution_timer(_random.paretovariate, 4.0, post_processor=_math.floor, num_cycles=num_cycles)
distribution_timer(paretovariate, 4.0, post_processor=_math.floor, num_cycles=num_cycles)
print("Base Case")
distribution_timer(_random.gauss, 1.0, 1.0, post_processor=round, num_cycles=num_cycles)
distribution_timer(gauss, 1.0, 1.0, post_processor=round, num_cycles=num_cycles)
print("Base Case")
distribution_timer(_random.normalvariate, 0.0, 2.8, post_processor=round, num_cycles=num_cycles)
distribution_timer(normalvariate, 0.0, 2.8, post_processor=round, num_cycles=num_cycles)
print("Base Case")
distribution_timer(_random.lognormvariate, 0.0, 0.5, post_processor=round, num_cycles=num_cycles)
distribution_timer(lognormvariate, 0.0, 0.5, post_processor=round, num_cycles=num_cycles)
print("Base Case")
distribution_timer(_random.vonmisesvariate, 0, 0, post_processor=_math.floor, num_cycles=num_cycles)
distribution_timer(vonmisesvariate, 0, 0, post_processor=_math.floor, num_cycles=num_cycles)
print("Base Case")
distribution_timer(_random.triangular, 0.0, 10.0, 0.0, post_processor=_math.floor, num_cycles=num_cycles)
distribution_timer(triangular, 0.0, 10.0, 0.0, post_processor=_math.floor, num_cycles=num_cycles)
some_list = [i for i in range(10)]
print("Base Case")
distribution_timer(_random.choice, some_list, num_cycles=num_cycles)
distribution_timer(choice, some_list, num_cycles=num_cycles)
weights = [i for i in reversed(range(1, 11))]
sample_size = 1
print("Base Case")
distribution_timer(_random.choices, some_list, weights, k=sample_size, num_cycles=num_cycles)
distribution_timer(choices, some_list, weights, k=sample_size, num_cycles=num_cycles)
cum_weights = list(_itertools.accumulate(weights))
print("Base Case")
distribution_timer(_random.choices, some_list, cum_weights=cum_weights, k=sample_size, num_cycles=num_cycles)
distribution_timer(choices, some_list, cum_weights=cum_weights, k=sample_size, num_cycles=num_cycles)
print("Base Case")
print(f"Timer only: random.shuffle(some_list) of size {len(some_list)}:")
timer(_random.shuffle, some_list, cycles=8)
print()
print(f"Timer only: shuffle(some_list) of size {len(some_list)}:")
timer(shuffle, some_list, cycles=8)
print()
print("Base Case")
distribution_timer(_random.sample, some_list, k=3, num_cycles=num_cycles)
distribution_timer(sample, some_list, k=3, num_cycles=num_cycles)
stop_test = _time.time()
print(f"\nTotal Test Time: {round(stop_test - start_test, 3)} sec")
if __name__ == "__main__":
quick_test()