Example #1
0
def main():
	if PYTHON=='PYTHONJS':
		pythonjs.configure( direct_operator='+' )
		pass

	start = time()
	n = 2000
	seq = []
	#cache = {0:True, 1:True, 2:True, 3:True}
	cache = []

	#w = worker(n,seq, cache)
	w1 = threading.start_webworker( worker, (0, n, seq, cache) )
	w2 = threading.start_webworker( worker, (10, n, seq, cache) )
	#w3 = threading.start_webworker( worker, (400, n, seq, cache) )
	sleep(1.0)

	testtime = time()-start
	primes_per_sec = len(seq) * (1.0 / testtime)

	#print('#%s' %len(seq))
	#seq.sort()  ## TODO fix sort for numbers
	print(primes_per_sec)
	print('#total test time: %s' %testtime)
	print('-----main exit')
Example #2
0
def main():
    if PYTHON == 'PYTHONJS':
        pythonjs.configure(direct_operator='+')
        pass

    seq = []
    w1 = threading.start_webworker(worker, (seq, 'A', 'B'))
    w2 = threading.start_webworker(worker, (seq, 'B', 'A'))

    sleep(1.0)

    TestError('A' in seq)
    TestError('B' in seq)
Example #3
0
def main():
	if PYTHON=='PYTHONJS':
		pythonjs.configure( direct_operator='+' )
		pass

	seq = []
	w1 = threading.start_webworker( worker, (seq, 'A', 'B') )
	w2 = threading.start_webworker( worker, (seq, 'B', 'A') )

	sleep(1.0)

	TestError( 'A' in seq )
	TestError( 'B' in seq )
Example #4
0
def main():
	w = threading.start_webworker( worker, [] )
	sleep(1.0)

	TestError( len(shared)==2 )
	TestError( shared[0]==10 )
	TestError( shared[1]==20 )
Example #5
0
def main():
    w = threading.start_webworker(worker, [])
    sleep(1.0)

    TestError(len(shared) == 2)
    TestError(shared[0] == 10)
    TestError(shared[1] == 20)
Example #6
0
def main():
	if PYTHON=='PYTHONJS':
		pythonjs.configure( direct_operator='+' )
		pass
	else:
		def l (f,a): threading._start_new_thread(f,a)
		threading.start_webworker = l

	seq = {}
	w1 = threading.start_webworker( worker, (seq, 'abcdefgh', 'i') )
	w2 = threading.start_webworker( worker, (seq, 'ijklmnop', 'p') )
	sleep(1.0)


	TestError( 'a' in seq )
	TestError( 'i' in seq )
	print('-----main exit')
	print(seq)
Example #7
0
def main():
	if PYTHON=='PYTHONJS':
		pythonjs.configure( direct_operator='+' )
		pass


	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


	starttime = time()
	n = 3000
	seq = []
	cache = []

	w1 = threading.start_webworker( worker, (0, n, seq, cache) )
	i = 0
	start = 1500
	step =10
	end = start + step
	while i < 10:
		for j in range(start, end):
			if j in cache:
				pass
			else:
				cache.append( j )
				if is_prime(j):
					seq.append( j )
		_ = start
		start = end
		end = _ + step
		i += 1
		sleep(0.1)


	testtime = time()-starttime
	primes_per_sec = len(seq) * (1.0 / testtime)
	print(primes_per_sec)
	print('#total test time: %s' %testtime)
	print('-----main exit')
Example #8
0
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')
Example #9
0
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')