From 4da93437c8c9cdd73a1f4f390b22b7dc625effa3 Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Wed, 3 May 2023 08:42:57 +0200 Subject: [PATCH] test: add benchmarks --- .github/workflows/ci.yml | 1 + pytest/test_simple_dep/app.config | 2 + pytest/test_simple_dep/config.import100.py | 1 + pytest/test_simple_dep/config1.py | 2 + pytest/test_simple_dep/config100.py | 2 + .../test_simple_dep/test_simple_dep_bench.py | 54 +++++++++++++++++++ 6 files changed, 62 insertions(+) create mode 100644 pytest/test_simple_dep/app.config create mode 100644 pytest/test_simple_dep/config.import100.py create mode 100644 pytest/test_simple_dep/config1.py create mode 100644 pytest/test_simple_dep/config100.py create mode 100644 pytest/test_simple_dep/test_simple_dep_bench.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4352682..7f0206a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,6 +28,7 @@ jobs: run: | python -m pip install --upgrade pip pip install pytest + pip install pytest-benchmark pip install . - name: Run pytest diff --git a/pytest/test_simple_dep/app.config b/pytest/test_simple_dep/app.config new file mode 100644 index 0000000..7f9c9f4 --- /dev/null +++ b/pytest/test_simple_dep/app.config @@ -0,0 +1,2 @@ +FOO = y +BAR = y diff --git a/pytest/test_simple_dep/config.import100.py b/pytest/test_simple_dep/config.import100.py new file mode 100644 index 0000000..b258056 --- /dev/null +++ b/pytest/test_simple_dep/config.import100.py @@ -0,0 +1 @@ +[kconfig_import("config.py") for _ in range(100)] diff --git a/pytest/test_simple_dep/config1.py b/pytest/test_simple_dep/config1.py new file mode 100644 index 0000000..a931a51 --- /dev/null +++ b/pytest/test_simple_dep/config1.py @@ -0,0 +1,2 @@ +for _ in range(1): + FOO.val = not FOO.val diff --git a/pytest/test_simple_dep/config100.py b/pytest/test_simple_dep/config100.py new file mode 100644 index 0000000..50b307b --- /dev/null +++ b/pytest/test_simple_dep/config100.py @@ -0,0 +1,2 @@ +for _ in range(100): + FOO.val = not FOO.val diff --git a/pytest/test_simple_dep/test_simple_dep_bench.py b/pytest/test_simple_dep/test_simple_dep_bench.py new file mode 100644 index 0000000..05dec9a --- /dev/null +++ b/pytest/test_simple_dep/test_simple_dep_bench.py @@ -0,0 +1,54 @@ +import os +import glob +import kconfiglib +import pytest + +CUR_DIR = os.path.dirname(os.path.realpath(__file__)) + + +def test_bench_config(benchmark): + """Evaluate the performance standard config file.""" + kconfig_path = CUR_DIR + '/Kconfig' + + kconf = kconfiglib.Kconfig(kconfig_path) + benchmark(kconf.load_config, filename=CUR_DIR + '/app.config') + + +def test_bench_configpy(benchmark): + """Evaluate the performance python config.""" + kconfig_path = CUR_DIR + '/Kconfig' + + kconf = kconfiglib.Kconfig(kconfig_path) + benchmark(kconf.load_config, filename=CUR_DIR + '/config.py') + + +def test_bench_import_configpy(benchmark): + """Evaluate the performance of importing.""" + kconfig_path = CUR_DIR + '/Kconfig' + + kconf = kconfiglib.Kconfig(kconfig_path) + benchmark(kconf.load_config, filename=CUR_DIR + '/config.import.py') + + +def test_bench_import100_configpy(benchmark): + """Evaluate the performance of importing foo 100 times.""" + kconfig_path = CUR_DIR + '/Kconfig' + + kconf = kconfiglib.Kconfig(kconfig_path) + benchmark(kconf.load_config, filename=CUR_DIR + '/config.import100.py') + + +def test_bench_config1_configpy(benchmark): + """Evaluate the performance of setting foo 1 time.""" + kconfig_path = CUR_DIR + '/Kconfig' + + kconf = kconfiglib.Kconfig(kconfig_path) + benchmark(kconf.load_config, filename=CUR_DIR + '/config1.py') + + +def test_bench_config100_configpy(benchmark): + """Evaluate the performance of setting foo 100 times.""" + kconfig_path = CUR_DIR + '/Kconfig' + + kconf = kconfiglib.Kconfig(kconfig_path) + benchmark(kconf.load_config, filename=CUR_DIR + '/config100.py')