File tree 3 files changed +16
-12
lines changed
3 files changed +16
-12
lines changed Original file line number Diff line number Diff line change @@ -9,15 +9,15 @@ def main():
9
9
10
10
t0 = datetime .datetime .now ()
11
11
12
- # do_math(num=30000000 )
12
+ # math_core. do_math(num=30_000_000 )
13
13
print ("Doing math on {:,} processors." .format (multiprocessing .cpu_count ()))
14
14
15
15
processor_count = multiprocessing .cpu_count ()
16
16
threads = []
17
17
for n in range (1 , processor_count + 1 ):
18
18
threads .append (Thread (target = math_core .do_math ,
19
- args = (30_000_000 * (n - 1 ) / processor_count ,
20
- 30_000_000 * n / processor_count ),
19
+ args = (300_000 * (n - 1 ) / processor_count ,
20
+ 300_000 * n / processor_count ),
21
21
daemon = True )
22
22
)
23
23
@@ -27,7 +27,7 @@ def main():
27
27
dt = datetime .datetime .now () - t0
28
28
print ("Done in {:,.2f} sec. (factor: {:,.2f}x)" .format (
29
29
dt .total_seconds (),
30
- 8.54 / dt .total_seconds ())
30
+ .09 / dt .total_seconds ())
31
31
)
32
32
33
33
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ def main():
7
7
8
8
t0 = datetime .datetime .now ()
9
9
10
- do_math (num = 30_000_000 )
10
+ do_math (num = 300_000 )
11
11
12
12
dt = datetime .datetime .now () - t0
13
13
print ("Done in {:,.2f} sec." .format (dt .total_seconds ()))
Original file line number Diff line number Diff line change 1
- import math
1
+ from libc. math cimport sqrt
2
2
3
- def do_math (start = 0 , num = 10 ):
4
- pos = start
5
- k_sq = 1000 * 1000
6
- while pos < num:
7
- pos += 1
8
- math.sqrt((pos - k_sq) * (pos - k_sq))
3
+ import cython
4
+
5
+ def do_math (start: cython.int = 0 , num: cython.int = 10 ):
6
+ pos: cython.int = start
7
+ k_sq: cython.int = 1000 * 1000
8
+
9
+ with nogil:
10
+ while pos < num:
11
+ pos += 1
12
+ sqrt((pos - k_sq) * (pos - k_sq))
You can’t perform that action at this time.
0 commit comments