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