-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest2.py
151 lines (134 loc) · 3.47 KB
/
test2.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
from typing import List, Union
from nodes import Value
from time import time
from random import randint
from dataclasses import dataclass
values = [Value(0), Value(1), Value('U'), Value("D"), Value("D'")]
# class TestClass:
# def __init__(self):
# self.values = [randint(1, 5) for _ in range(0, 2)]
#
# def __repr__(self):
# return str(self.values)
@dataclass
class Count:
true = 0
false = 0
@classmethod
def by_ifelse(cls, a: List[Value], b: List[Value]):
obj = cls()
for xval, yval in zip(a, b):
if xval == 0 and yval == 0:
obj.true += 1
elif xval == 1 and yval == 1:
obj.true += 1
elif xval == "U" and yval == "U":
obj.true += 1
elif xval == "D" and yval == "D":
obj.true += 1
elif xval == "D'" and yval == "D'":
obj.true += 1
else:
obj.false += 1
return obj
@classmethod
def by_map(cls, a: List[Value], b: List[Value]):
obj = cls()
for xval, yval in zip(a, b):
member = base[xval].get(yval, 'false')
setattr(obj, member, getattr(obj, member) + 1)
# obj.__dict__[
# base[xval].get(yval, 'false')
# ] += 1
return obj
@classmethod
def by_map_string(cls, a: List[Value], b: List[Value]):
obj = cls()
for xval, yval in zip(a, b):
member = base_string[str(xval)].get(str(yval), 'false')
setattr(obj, member, getattr(obj, member) + 1)
# obj.__dict__[
# base[xval].get(yval, 'false')
# ] += 1
return obj
base_string = {
0: {'0': 'true'},
1: {'1': 'true'},
'U': {'U': 'true'},
"D": {"D": 'true'},
"D'": {"D'": 'true'}
}
base = {
Value(0): {Value(0): 'true'},
Value(1): {Value(1): 'true'},
Value('U'): {Value("U"): 'true'},
Value("D"): {Value("D"): 'true'},
Value("D'"): {Value("D'"): 'true'}
}
@dataclass
class Input:
zero = False
one = False
unknown = False
d = False
dprime = False
if __name__ == '__main__':
start = time()
input = Input()
end = time()
print(end - start)
start = time()
zero = False
one = False
unknown = False
d = False
dprime = False
zero = True
one = True
unknown = True
one = True
d = True
zero = True
one = True
unknown = True
dprime = True
zero = False
one = False
unknown = False
d = False
dprime = False
end = time()
print(end - start)
# _key: List[Value] = [values[randint(0, 4)] for _ in range(0, 1000)]
# y: List[Value] = [values[randint(0, 4)] for _ in range(0, 1000)]
# start = time()
# by_map = Count.by_map(_key, y)
# end = time()
# print(f"By map: {end - start}")
# start = time()
# by_ifelse = Count.by_ifelse(_key, y)
# end = time()
# print(f"By ifelse: {end - start}")
# start = time()
# by_map_string = Count.by_map_string(_key, y)
# end = time()
# print(f"By map_string: {end - start}")
from time import time
from random import randint
ints = []
ones = []
start = time()
for _ in range(1, 100000):
rint = randint(1, 2)
if rint == 1:
ones.append(rint)
end = time()
print(end - start)
ints = []
ones = []
start = time()
for _ in range(1, 100000):
rint = randint(1, 2)
ones = [n for n in ints if n == 1]
end = time()
print(end - start)