File tree 5 files changed +25
-10
lines changed 5 files changed +25
-10
lines changed Original file line number Diff line number Diff line change @@ -139,3 +139,4 @@ src/11-cython/.idea/misc.xml
139
139
src /11-cython /.idea /modules.xml
140
140
src /11-cython /.idea /workspace.xml
141
141
greeter.c
142
+ math_core.c
Original file line number Diff line number Diff line change 1
1
import datetime
2
- import math
2
+ import math_core
3
3
from threading import Thread
4
4
import multiprocessing
5
5
6
6
7
7
def main ():
8
- do_math (1 )
8
+ math_core . do_math (1 )
9
9
10
10
t0 = datetime .datetime .now ()
11
11
@@ -15,7 +15,7 @@ def main():
15
15
processor_count = multiprocessing .cpu_count ()
16
16
threads = []
17
17
for n in range (1 , processor_count + 1 ):
18
- threads .append (Thread (target = do_math ,
18
+ threads .append (Thread (target = math_core . do_math ,
19
19
args = (30_000_000 * (n - 1 ) / processor_count ,
20
20
30_000_000 * n / processor_count ),
21
21
daemon = True )
@@ -31,12 +31,12 @@ def main():
31
31
)
32
32
33
33
34
- def do_math (start = 0 , num = 10 ):
35
- pos = start
36
- k_sq = 1000 * 1000
37
- while pos < num :
38
- pos += 1
39
- math .sqrt ((pos - k_sq ) * (pos - k_sq ))
34
+ # def do_math(start=0, num=10):
35
+ # pos = start
36
+ # k_sq = 1000 * 1000
37
+ # while pos < num:
38
+ # pos += 1
39
+ # math.sqrt((pos - k_sq) * (pos - k_sq))
40
40
41
41
42
42
if __name__ == '__main__' :
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 = 30000000 )
10
+ do_math (num = 30_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
1
+ import math
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))
Original file line number Diff line number Diff line change
1
+ from distutils .core import setup
2
+ from Cython .Build import cythonize
3
+
4
+ setup (
5
+ ext_modules = cythonize ("math_core.pyx" )
6
+ )
You can’t perform that action at this time.
0 commit comments