Skip to content

Commit 2a05f05

Browse files
committed
tests/bench: Add tests for various ways to pass function args.
Passing 3 args with keywords is for example 50% slower than via positional args.
1 parent 1695151 commit 2a05f05

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed

tests/bench/func_args-1.1-pos_1.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import bench
2+
3+
def func(a):
4+
pass
5+
6+
def test(num):
7+
for i in iter(range(num)):
8+
func(i)
9+
10+
bench.run(test)

tests/bench/func_args-1.2-pos_3.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import bench
2+
3+
def func(a, b, c):
4+
pass
5+
6+
def test(num):
7+
for i in iter(range(num)):
8+
func(i, i, i)
9+
10+
bench.run(test)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import bench
2+
3+
def func(a, b=1, c=2):
4+
pass
5+
6+
def test(num):
7+
for i in iter(range(num)):
8+
func(i)
9+
10+
bench.run(test)

tests/bench/func_args-3.1-kw_1.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import bench
2+
3+
def func(a):
4+
pass
5+
6+
def test(num):
7+
for i in iter(range(num)):
8+
func(a=i)
9+
10+
bench.run(test)

tests/bench/func_args-3.2-kw_3.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import bench
2+
3+
def func(a, b, c):
4+
pass
5+
6+
def test(num):
7+
for i in iter(range(num)):
8+
func(c=i, b=i, a=i)
9+
10+
bench.run(test)

0 commit comments

Comments
 (0)