-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathwebworker_single.py
More file actions
54 lines (42 loc) · 927 Bytes
/
Copy pathwebworker_single.py
File metadata and controls
54 lines (42 loc) · 927 Bytes
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
'''
webworker single
'''
from time import time
from time import sleep
import threading
def main():
if PYTHON=='PYTHONJS':
pythonjs.configure( direct_operator='+' )
pass
starttime = time()
n = 3000
seq = []
cache = []
w1 = threading.start_webworker( worker, (0, n, seq, cache) )
sleep(1.0)
testtime = time()-starttime
primes_per_sec = len(seq) * (1.0 / testtime)
print(primes_per_sec)
print('#total test time: %s' %testtime)
print('-----main exit')
with webworker:
def worker(start, end, seq, cache):
print('------enter worker------')
for i in range(start, end):
if i in cache:
#continue ## TODO - fix continue
pass
else:
cache.append( i )
if is_prime(i):
seq.append( i )
print('#worker reached: %s' %i)
def is_prime(n):
hits = 0
for x in range(2, n):
for y in range(2, n):
if x*y == n:
hits += 1
if hits > 1:
return False
return True