File tree Expand file tree Collapse file tree 3 files changed +60
-0
lines changed Expand file tree Collapse file tree 3 files changed +60
-0
lines changed Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments