From 17d3f497b1bdd0a39a8092616e671d215f211268 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sun, 18 Feb 2024 20:29:44 +0100 Subject: [PATCH] Run simple benchmarks as part of CI. --- .github/workflows/ci.yml | 10 ++++++++++ benchmark/microbench.py | 12 +++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2298214..bee950f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -140,6 +140,11 @@ jobs: path: dist/*.whl if-no-files-found: ignore + - name: Running benchmark + run: | + python benchmark/telco_fractions.py + python benchmark/microbench.py create pydigits + non-Linux: strategy: # Allows for matrix sub-jobs to fail without canceling the rest @@ -193,3 +198,8 @@ jobs: name: wheels-${{ matrix.os }} path: dist/*.whl if-no-files-found: ignore + + - name: Running benchmark + run: | + python benchmark/telco_fractions.py + python benchmark/microbench.py create pydigits diff --git a/benchmark/microbench.py b/benchmark/microbench.py index 22ae2ce..ef2cad7 100644 --- a/benchmark/microbench.py +++ b/benchmark/microbench.py @@ -1,13 +1,23 @@ import datetime import itertools import operator +import os import statistics import timeit from collections import defaultdict from decimal import Decimal from fractions import Fraction as PyFraction -from quicktions import Fraction as QFraction + +def rel_path(*path): + return os.path.join(os.path.dirname(__file__), *path) + +try: + from quicktions import Fraction as QFraction +except ImportError: + import sys + sys.path.insert(0, rel_path('..', 'src')) + from quicktions import Fraction as QFraction PyFraction.__name__ = "PyFraction"