File tree Expand file tree Collapse file tree 3 files changed +42
-0
lines changed
pyperformance/data-files/benchmarks Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ async_tree <local>
6
6
async_tree_cpu_io_mixed <local:async_tree>
7
7
async_tree_io <local:async_tree>
8
8
async_tree_memoization <local:async_tree>
9
+ coroutines <local>
9
10
coverage <local>
10
11
generators <local>
11
12
chameleon <local>
Original file line number Diff line number Diff line change
1
+ [project ]
2
+ name = " pyperformance_bm_coroutines"
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 = " coroutines"
Original file line number Diff line number Diff line change
1
+ """
2
+ Benchmark for recursive coroutines.
3
+
4
+ Author: Kumar Aditya
5
+ """
6
+
7
+ import pyperf
8
+
9
+
10
+ async def fibonacci (n : int ) -> int :
11
+ if n <= 1 :
12
+ return n
13
+ return await fibonacci (n - 1 ) + await fibonacci (n - 2 )
14
+
15
+
16
+ def bench_coroutines (loops : int ) -> float :
17
+ range_it = range (loops )
18
+ t0 = pyperf .perf_counter ()
19
+ for _ in range_it :
20
+ coro = fibonacci (25 )
21
+ try :
22
+ while True :
23
+ coro .send (None )
24
+ except StopIteration :
25
+ pass
26
+ return pyperf .perf_counter () - t0
27
+
28
+
29
+ if __name__ == "__main__" :
30
+ runner = pyperf .Runner ()
31
+ runner .metadata ['description' ] = "Benchmark coroutines"
32
+ runner .bench_time_func ('coroutines' , bench_coroutines )
You can’t perform that action at this time.
0 commit comments