Skip to content

Commit bf4e9cd

Browse files
committed
adding thread tests
1 parent eb99e82 commit bf4e9cd

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sys
2+
import time, random
3+
from concurrent.futures import ThreadPoolExecutor
4+
5+
print(f"nogil={getattr(sys.flags, 'nogil', False)}")
6+
7+
def fib(n):
8+
if n < 2: return 1
9+
return fib(n-1) + fib(n-2)
10+
11+
threads = 1
12+
start = time.time()
13+
if len(sys.argv) > 1:
14+
threads = int(sys.argv[1])
15+
16+
with ThreadPoolExecutor(max_workers=threads) as executor:
17+
for _ in range(threads):
18+
executor.submit(lambda: print(fib(34)))
19+
t = time.time()-start
20+
print("Solved g %.2f secs " %t)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sys
2+
import time, random
3+
from concurrent.futures import ThreadPoolExecutor
4+
5+
print(f"nogil={getattr(sys.flags, 'nogil', False)}")
6+
7+
def fib(n):
8+
if n < 2: return 1
9+
return fib(n-1) + fib(n-2)
10+
11+
threads = 20
12+
start = time.time()
13+
if len(sys.argv) > 1:
14+
threads = int(sys.argv[1])
15+
16+
with ThreadPoolExecutor(max_workers=threads) as executor:
17+
for _ in range(threads):
18+
executor.submit(lambda: print(fib(34)))
19+
t = time.time()-start
20+
print("Solved g %.2f secs " %t)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sys
2+
import time, random
3+
from concurrent.futures import ThreadPoolExecutor
4+
5+
print(f"nogil={getattr(sys.flags, 'nogil', False)}")
6+
7+
def fib(n):
8+
if n < 2: return 1
9+
return fib(n-1) + fib(n-2)
10+
11+
threads = 4
12+
start = time.time()
13+
if len(sys.argv) > 1:
14+
threads = int(sys.argv[1])
15+
16+
with ThreadPoolExecutor(max_workers=threads) as executor:
17+
for _ in range(threads):
18+
executor.submit(lambda: print(fib(34)))
19+
t = time.time()-start
20+
print("Solved g %.2f secs " %t)

0 commit comments

Comments
 (0)