Skip to content

Commit a975dc6

Browse files
authored
Merge pull request #88 from stonebig/master
adding thread tests
2 parents e11e926 + bf4e9cd commit a975dc6

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

docs/free-threading_test/thread1.py

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)

docs/free-threading_test/thread20.py

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)

docs/free-threading_test/thread4.py

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)