Skip to content

Commit f8a4919

Browse files
authored
Add some benchmarks (#1527)
The part of #1517 related to the benchmarks.
1 parent 23a54d0 commit f8a4919

File tree

4 files changed

+84
-1
lines changed

4 files changed

+84
-1
lines changed

.github/workflows/ubuntu-bench.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Mathics3 Basic Benchmarks(ubuntu)
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: '**'
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ['3.13', '3.12', '3.11', '3.10']
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Set up Python ${{ matrix.python-version }}
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
- name: Install OS dependencies
22+
run: |
23+
sudo apt-get update -qq && sudo apt-get install -qq liblapack-dev llvm-dev tesseract-ocr remake
24+
- name: Install Mathics3 with full dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
python -m pip install pytest-benchmark
28+
# First install our patched version of stopit
29+
git clone --depth 1 https://github.com/Mathics3/stopit.git
30+
cd stopit/
31+
pip install -e .
32+
cd ..
33+
# We can comment out after next Mathics-Scanner release
34+
# python -m pip install Mathics-Scanner[full]
35+
# python -m pip install -e git+https://github.com/Mathics3/mathics-scanner#egg=Mathics-Scanner[full]
36+
pip install -e .
37+
remake -x develop
38+
- name: Test Mathics
39+
run: |
40+
remake benchmarks

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ MATHICS3_MODULE_OPTION ?= --load-module pymathics.graph,pymathics.natlang
1717

1818
.PHONY: \
1919
all \
20+
benchmarks \
2021
build \
2122
check \
2223
check-builtin-manifest \
@@ -54,6 +55,10 @@ endif
5455
#: Default target - same as "develop"
5556
all: develop
5657

58+
# run pytest benchmarks
59+
benchmarks:
60+
BENCHMARKS=True $(PYTHON) -m pytest $(PYTEST_OPTIONS) test/timings
61+
5762
#: build everything needed to install
5863
build:
5964
$(PYTHON) ./setup.py build
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os
2+
import sys
3+
import time
4+
from test.helper import check_evaluation, evaluate, session
5+
6+
import pytest
7+
8+
if os.environ.get("BENCHMARKS", 0):
9+
session.reset()
10+
session.evaluate("F[__Real]:=1;")
11+
table_uniform_expr = session.evaluate("uniformTable=Table[1./(1.+i^2),{i,0,1000}]")
12+
table_non_uniform_expr = session.evaluate(
13+
"nonuniformTable=Table[If[i==0,1,1./(1.+i^2)],{i, 0,1000}]"
14+
)
15+
# assert table_uniform_expr.elements_properties.is_uniform
16+
# assert not table_non_uniform_expr.elements_properties.is_uniform
17+
18+
19+
@pytest.mark.skipif(
20+
not os.environ.get("BENCHMARKS", 0), reason="benchmarks not required"
21+
)
22+
@pytest.mark.parametrize(
23+
["expr", "expect"],
24+
[
25+
("Plus@@uniformTable", "2.075674547634748"),
26+
("MatchQ[uniformTable,{__Real}]", "System`True"),
27+
("Length[F@@uniformTable]", "0"),
28+
("Plus@@nonuniformTable", "2.075674547634748"),
29+
("MatchQ[nonuniformTable,{__Real}]", "System`False"),
30+
("Length[F@@nonuniformTable]", "1001"),
31+
],
32+
)
33+
def test_evaluate_benchmark(benchmark, expr, expect):
34+
# TODO: rewrite this to be used with pytest-benchmark
35+
def impl():
36+
assert str(session.evaluate(expr)) == expect
37+
38+
benchmark.pedantic(impl, rounds=10, iterations=2)

0 commit comments

Comments
 (0)