From 2a05f05f4468bc937e412e94df75da9dce9a6148 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 7 May 2014 21:39:09 +0300 Subject: [PATCH] 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. --- tests/bench/func_args-1.1-pos_1.py | 10 ++++++++++ tests/bench/func_args-1.2-pos_3.py | 10 ++++++++++ tests/bench/func_args-2-pos_default_2_of_3.py | 10 ++++++++++ tests/bench/func_args-3.1-kw_1.py | 10 ++++++++++ tests/bench/func_args-3.2-kw_3.py | 10 ++++++++++ 5 files changed, 50 insertions(+) create mode 100644 tests/bench/func_args-1.1-pos_1.py create mode 100644 tests/bench/func_args-1.2-pos_3.py create mode 100644 tests/bench/func_args-2-pos_default_2_of_3.py create mode 100644 tests/bench/func_args-3.1-kw_1.py create mode 100644 tests/bench/func_args-3.2-kw_3.py diff --git a/tests/bench/func_args-1.1-pos_1.py b/tests/bench/func_args-1.1-pos_1.py new file mode 100644 index 0000000000..eee0ea8289 --- /dev/null +++ b/tests/bench/func_args-1.1-pos_1.py @@ -0,0 +1,10 @@ +import bench + +def func(a): + pass + +def test(num): + for i in iter(range(num)): + func(i) + +bench.run(test) diff --git a/tests/bench/func_args-1.2-pos_3.py b/tests/bench/func_args-1.2-pos_3.py new file mode 100644 index 0000000000..7e03ee2f85 --- /dev/null +++ b/tests/bench/func_args-1.2-pos_3.py @@ -0,0 +1,10 @@ +import bench + +def func(a, b, c): + pass + +def test(num): + for i in iter(range(num)): + func(i, i, i) + +bench.run(test) diff --git a/tests/bench/func_args-2-pos_default_2_of_3.py b/tests/bench/func_args-2-pos_default_2_of_3.py new file mode 100644 index 0000000000..1fa0fbda59 --- /dev/null +++ b/tests/bench/func_args-2-pos_default_2_of_3.py @@ -0,0 +1,10 @@ +import bench + +def func(a, b=1, c=2): + pass + +def test(num): + for i in iter(range(num)): + func(i) + +bench.run(test) diff --git a/tests/bench/func_args-3.1-kw_1.py b/tests/bench/func_args-3.1-kw_1.py new file mode 100644 index 0000000000..7bc81e5bea --- /dev/null +++ b/tests/bench/func_args-3.1-kw_1.py @@ -0,0 +1,10 @@ +import bench + +def func(a): + pass + +def test(num): + for i in iter(range(num)): + func(a=i) + +bench.run(test) diff --git a/tests/bench/func_args-3.2-kw_3.py b/tests/bench/func_args-3.2-kw_3.py new file mode 100644 index 0000000000..7f95106841 --- /dev/null +++ b/tests/bench/func_args-3.2-kw_3.py @@ -0,0 +1,10 @@ +import bench + +def func(a, b, c): + pass + +def test(num): + for i in iter(range(num)): + func(c=i, b=i, a=i) + +bench.run(test)