Skip to content

Commit b1e70ce

Browse files
committed
Final code for Cython threading (float version)
1 parent 056395a commit b1e70ce

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

Diff for: src/11-cython/perf/compute_cython.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@
77
def main():
88
math_core.do_math(1)
99

10-
t0 = datetime.datetime.now()
11-
12-
# math_core.do_math(num=30_000_000)
1310
print("Doing math on {:,} processors.".format(multiprocessing.cpu_count()))
1411

1512
processor_count = multiprocessing.cpu_count()
1613
threads = []
1714
for n in range(1, processor_count + 1):
1815
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),
2118
daemon=True)
2219
)
2320

21+
t0 = datetime.datetime.now()
2422
[t.start() for t in threads]
23+
2524
[t.join() for t in threads]
25+
# math_core.do_math(num=300_000)
2626

2727
dt = datetime.datetime.now() - t0
2828
print("Done in {:,.2f} sec. (factor: {:,.2f}x)".format(
2929
dt.total_seconds(),
30-
.09/dt.total_seconds())
30+
0.80 / dt.total_seconds())
3131
)
3232

3333

Diff for: src/11-cython/perf/compute_it.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def main():
77

88
t0 = datetime.datetime.now()
99

10-
do_math(num=300_000)
10+
do_math(num=3_000_000)
1111

1212
dt = datetime.datetime.now() - t0
1313
print("Done in {:,.2f} sec.".format(dt.total_seconds()))

Diff for: src/11-cython/perf/math_core.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ from libc.math cimport sqrt
22

33
import cython
44

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
88

99
with nogil:
1010
while pos < num:

0 commit comments

Comments
 (0)