Skip to content

Commit 81af6f2

Browse files
authored
bm_concurrent_imap: Add benchmark for IPC (gh-228)
1 parent caf63ec commit 81af6f2

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

pyperformance/data-files/benchmarks/MANIFEST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ async_tree <local>
66
async_tree_cpu_io_mixed <local:async_tree>
77
async_tree_io <local:async_tree>
88
async_tree_memoization <local:async_tree>
9+
concurrent_imap <local>
910
coroutines <local>
1011
coverage <local>
1112
generators <local>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[project]
2+
name = "pyperformance_bm_concurrent_imap"
3+
requires-python = ">=3.8"
4+
dependencies = ["pyperf"]
5+
urls = {repository = "https://github.com/python/pyperformance"}
6+
dynamic = ["version"]
7+
8+
[tool.pyperformance]
9+
name = "concurrent_imap"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
Benchmark for concurrent model communication.
3+
"""
4+
import pyperf
5+
6+
from multiprocessing.pool import Pool, ThreadPool
7+
8+
9+
def f(x: int) -> int:
10+
return x
11+
12+
13+
def bench_mp_pool(p: int, n: int, chunk: int) -> None:
14+
with Pool(p) as pool:
15+
for _ in pool.imap(f, range(n), chunk):
16+
pass
17+
18+
19+
def bench_thread_pool(c: int, n: int, chunk: int) -> None:
20+
with ThreadPool(c) as pool:
21+
for _ in pool.imap(f, range(n), chunk):
22+
pass
23+
24+
25+
if __name__ == "__main__":
26+
runner = pyperf.Runner()
27+
runner.metadata["description"] = "concurrent model communication benchmark"
28+
count = 1000
29+
chunk = 10
30+
num_core = 2
31+
runner.bench_func("bench_mp_pool", bench_mp_pool, num_core, count, chunk)
32+
runner.bench_func("bench_thread_pool", bench_thread_pool, num_core, count, chunk)

0 commit comments

Comments
 (0)