Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a975dc6

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

File tree

Expand file treeCollapse file tree

3 files changed

+60
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+60
-0
lines changed

‎docs/free-threading_test/thread1.py

Copy file name to clipboard
+20Lines 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

Copy file name to clipboard
+20Lines 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

Copy file name to clipboard
+20Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.