From 5f62a0ee12cd31cbe466e2e91b2fdf4dcb377355 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 8 Aug 2024 10:22:46 +0100 Subject: [PATCH] add benchmarks --- .github/workflows/benchmark.yml | 34 +++++++++++++++++++++++++++++++++ benchmark.py | 16 ++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 .github/workflows/benchmark.yml create mode 100644 benchmark.py diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml new file mode 100644 index 0000000..2daeb8d --- /dev/null +++ b/.github/workflows/benchmark.yml @@ -0,0 +1,34 @@ +name: KGL Benchmark (1M queries) + +on: + pull_request: + branches: [main] + push: + branches: [main] + +jobs: + build-dev-test: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: ["ubuntu-latest", "macos-latest", "windows-latest"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + steps: + - name: ๐Ÿ›Ž๏ธ Checkout + uses: actions/checkout@v4 + - name: ๐Ÿ Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + check-latest: true + + - name: ๐Ÿ“ฆ Install dependencies + run: | + python -m pip install --upgrade pip + pip install . + pip install pytest + + - name: ๐Ÿงช Test + env: + SITE_ENV: production + run: "python benchmark.py" \ No newline at end of file diff --git a/benchmark.py b/benchmark.py new file mode 100644 index 0000000..cb912a3 --- /dev/null +++ b/benchmark.py @@ -0,0 +1,16 @@ +import os +from kgl import KnowledgeGraph +import cProfile + +TEST_ITERATIONS = 1_000_000 + +test_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "test") + +kg = KnowledgeGraph().load_from_csv(os.path.join(test_dir, "data", "example.csv")) + +def main(): + for i in range(TEST_ITERATIONS): + kg.evaluate("{ James -> Likes }") + +# save the profile results +cProfile.run("main()", sort="cumtime", filename="profile_results") \ No newline at end of file