FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add benchmarks for some of the basic operations on some of the basic types by Maegereg · Pull Request #349 · flintlib/python-flint · GitHub

Repository navigation

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
183 changes: 183 additions & 0 deletions benchmarks/simple_benchmarks.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
"""Benchmarks for basic operations of a number of flint types.

These benchmarks are written using pyperf, and can be run by

python benchmarks/simple_benchmarks.py

Since each benchmark is very short ("microbenchmarks"), they may
require an increased number of samples to produce statistically
significant results (via the --values flag).
"""

import pyperf
from utils import get_all_benchmarks

NUM_EXECUTIONS = 10000000


def benchmark_arb_addition(runner: pyperf.Runner):
"""Simple benchmark for adding two arbs."""
runner.timeit(
name="arb addition",
setup=[
"from flint import arb",
"a = arb(1, 2)",
"b = arb.pi()",
],
stmt="a + b"
)


def benchmark_arb_multiplication(runner: pyperf.Runner):
"""Simple benchmark for multiplying two arbs."""
runner.timeit(
name="arb multiplication",
setup=[
"from flint import arb",
"a = arb(1, 2)",
"b = arb.pi()",
],
stmt="a * b"
)


def benchmark_arb_contains(runner: pyperf.Runner):
"""Simple benchmark for comparing two arbs."""
runner.timeit(
name="arb contains",
setup=[
"from flint import arb",
"a = arb(1, 2)",
"b = arb.pi()",
],
stmt=[
"a in b",
"b in a",
]
)


def benchmark_fmpz_addition(runner: pyperf.Runner):
"""Simple benchmark for adding two fmpzs."""
runner.timeit(
name="fmpz addition",
setup=[
"from flint import fmpz",
"a = fmpz(1)",
"b = fmpz(6)",
],
stmt="a + b"
)

def benchmark_fmpz_multiplication(runner: pyperf.Runner):
"""Simple benchmark for multiplying two fmpzs."""
runner.timeit(
name="fmpz multiplication",
setup=[
"from flint import fmpz",
"a = fmpz(1)",
"b = fmpz(6)",
],
stmt="a * b"
)


def benchmark_fmpz_eq(runner: pyperf.Runner):
"""Simple benchmark for equality on two fmpzs."""
runner.timeit(
name="fmpz equality",
setup=[
"from flint import fmpz",
"a = fmpz(1)",
"b = fmpz(6)",
],
stmt=["a == b", "b == a"]
)


def benchmark_fmpq_addition(runner: pyperf.Runner):
"""Simple benchmark for adding two fmpqs."""
runner.timeit(
name="fmpq addition",
setup=[
"from flint import fmpq",
"a = fmpq(1, 2)",
"b = fmpq(15, 7)",
],
stmt="a + b"
)


def benchmark_fmpq_multiplication(runner: pyperf.Runner):
"""Simple benchmark for multiplying two fmpqs."""
runner.timeit(
name="fmpq multiplication",
setup=[
"from flint import fmpq",
"a = fmpq(1, 2)",
"b = fmpq(15, 7)",
],
stmt="a * b"
)


def benchmark_fmpq_eq(runner: pyperf.Runner):
"""Simple benchmark for equality on two fmpqs."""
runner.timeit(
name="fmpq equality",
setup=[
"from flint import fmpq",
"a = fmpq(1, 2)",
"b = fmpq(15, 7)",
],
stmt=["a == b", "b == a"]
)


def benchmark_acb_addition(runner: pyperf.Runner):
"""Simple benchmark for adding two acbs."""
runner.timeit(
name="acb addition",
setup=[
"from flint import acb",
"a = acb(1 + 3j)",
"b = acb.pi()",
],
stmt="a + b"
)


def benchmark_acb_multiplication(runner: pyperf.Runner):
"""Simple benchmark for multiplying two acbs."""
runner.timeit(
name="acb multiplication",
setup=[
"from flint import acb",
"a = acb(1 + 3j)",
"b = acb.pi()",
],
stmt="a * b"
)


def benchmark_acb_eq(runner: pyperf.Runner):
"""Simple benchmark for containment on two acbs."""
runner.timeit(
name="acb contains",
setup=[
"from flint import acb",
"a = acb(1 + 3j)",
"b = acb.pi()",
],
stmt=["a in b", "b in a"]
)

def main():
"""Run all the benchmarks."""
runner = pyperf.Runner()
benchmarks = get_all_benchmarks(__name__)
for benchmark in benchmarks:
benchmark(runner)

if __name__ == "__main__":
main()
13 changes: 13 additions & 0 deletions benchmarks/utils.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Utility functions for benchmarking."""

import inspect
import sys


def get_all_benchmarks(modulename):
"""Returns a list of all functions in the current module named 'benchmark_*'."""
return [
obj
for name, obj in inspect.getmembers(sys.modules[modulename])
if inspect.isfunction(obj) and name.startswith("benchmark_")
]
Loading

Back | FazBrowse Home | New Git URL