-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
👷 build(benchmarks): add more benchmarks and config (#363)
* 👷 build(benchmarks): add more benchmarks and config * ⬆️ dep-bump(deps): bump and set optional dependency pins Signed-off-by: Nathaniel Starkman <[email protected]>
- Loading branch information
Showing
8 changed files
with
363 additions
and
202 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1 +1 @@ | ||
3.11 | ||
3.12 |
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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,78 @@ | ||
"""Benchmark tests for quaxified jax.""" | ||
|
||
import equinox as eqx | ||
import jax | ||
import pytest | ||
from jaxlib.xla_extension import PjitFunction | ||
|
||
import unxt as u | ||
|
||
|
||
@pytest.fixture | ||
def func_dimension() -> PjitFunction: | ||
return eqx.filter_jit(u.dimension) | ||
|
||
|
||
@pytest.fixture | ||
def func_dimension_of() -> PjitFunction: | ||
return eqx.filter_jit(u.dimension_of) | ||
|
||
|
||
##################################################################### | ||
# `dimension` | ||
|
||
args = [(u.dimension("length"),), ("length",)] | ||
|
||
|
||
@pytest.mark.parametrize("args", args, ids=str) | ||
@pytest.mark.benchmark(group="dimensions", warmup=False, max_time=1.0) | ||
def test_dimension(args): | ||
"""Test calling `unxt.dimension`.""" | ||
_ = u.dimension(*args) | ||
|
||
|
||
@pytest.mark.parametrize("args", args, ids=str) | ||
@pytest.mark.benchmark(group="dimensions", warmup=False, max_time=1.0) | ||
def test_dimension_jit_compile(func_dimension, args): | ||
"""Test the speed of jitting.""" | ||
_ = func_dimension.lower(*args).compile() | ||
|
||
|
||
@pytest.mark.parametrize("args", args, ids=str) | ||
@pytest.mark.benchmark(group="dimensions", warmup=True, max_time=1.0) | ||
def test_dimension_execute(func_dimension, args): | ||
"""Test the speed of calling the function.""" | ||
_ = jax.block_until_ready(func_dimension(*args)) | ||
|
||
|
||
##################################################################### | ||
# `dimension_of` | ||
|
||
|
||
args = [ | ||
(u.dimension("length"),), # -> Dimension('length') | ||
(u.unit("m"),), # -> Dimension('length') | ||
(u.Quantity(1, "m"),), # -> Dimension('length') | ||
(2,), # -> None | ||
] | ||
|
||
|
||
@pytest.mark.parametrize("args", args, ids=str) | ||
@pytest.mark.benchmark(group="dimensions", warmup=False, max_time=1.0) | ||
def test_dimension_of(args): | ||
"""Test calling `unxt.dimension_of`.""" | ||
_ = u.dimension_of(*args) | ||
|
||
|
||
@pytest.mark.parametrize("args", args, ids=str) | ||
@pytest.mark.benchmark(group="dimensions", warmup=False, max_time=1.0) | ||
def test_dimension_of_jit_compile(func_dimension_of, args): | ||
"""Test the speed of jitting.""" | ||
_ = func_dimension_of.lower(*args).compile() | ||
|
||
|
||
@pytest.mark.parametrize("args", args, ids=str) | ||
@pytest.mark.benchmark(group="dimensions", warmup=True, max_time=1.0) | ||
def test_dimension_of_execute(func_dimension_of, args): | ||
"""Test the speed of calling the function.""" | ||
_ = jax.block_until_ready(func_dimension_of(*args)) |
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,78 +1,73 @@ | ||
"""Benchmark tests for `unxt.units`.""" | ||
|
||
import equinox as eqx | ||
import jax | ||
import pytest | ||
from jaxlib.xla_extension import PjitFunction | ||
|
||
import unxt as u | ||
|
||
METER = u.unit("m") | ||
|
||
|
||
@pytest.fixture | ||
def func_unit_is_length(): | ||
return lambda x: u.unit(x) == METER | ||
def func_unit() -> PjitFunction: | ||
return eqx.filter_jit(u.unit) | ||
|
||
|
||
@pytest.fixture | ||
def func_unit_of_length(): | ||
return lambda x: u.unit_of(x) == METER | ||
def func_unit_of() -> PjitFunction: | ||
# need to filter_jit because arg can be a array or other object | ||
return eqx.filter_jit(u.unit_of) | ||
|
||
|
||
##################################################################### | ||
# `unit` | ||
|
||
args = [(u.unit("meter"),), ("meter",)] | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"args", | ||
[ | ||
(u.unit("meter"),), # -> Unit('meter') | ||
("meter",), # -> Unit('meter') | ||
], | ||
) | ||
@pytest.mark.benchmark(group="units", warmup=False) | ||
@pytest.mark.parametrize("args", args, ids=str) | ||
@pytest.mark.benchmark(group="units", warmup=False, max_time=1.0) | ||
def test_unit(args): | ||
"""Test calling `unxt.unit`.""" | ||
_ = u.unit(*args) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"args", | ||
[ | ||
(u.unit("meter"),), # -> Unit('meter') | ||
("meter",), # -> Unit('meter') | ||
], | ||
) | ||
@pytest.mark.benchmark(group="units", warmup=True) | ||
def test_unit_execute(func_unit_is_length, args): | ||
@pytest.mark.parametrize("args", args, ids=str) | ||
@pytest.mark.benchmark(group="units", warmup=True, max_time=1.0) | ||
def test_unit_jit_compile(func_unit, args): | ||
"""Test the speed of calling the function.""" | ||
_ = func_unit.lower(*args).compile() | ||
|
||
|
||
@pytest.mark.parametrize("args", args, ids=str) | ||
@pytest.mark.benchmark(group="units", warmup=True, max_time=1.0) | ||
def test_unit_execute(func_unit, args): | ||
"""Test the speed of calling the function.""" | ||
_ = jax.block_until_ready(func_unit_is_length(*args)) | ||
_ = jax.block_until_ready(func_unit(*args)) | ||
|
||
|
||
##################################################################### | ||
# `unit_of` | ||
|
||
args = [(u.unit("meter"),), (u.Quantity(1, "m"),), (2,)] | ||
|
||
@pytest.mark.parametrize( | ||
"args", | ||
[ | ||
(u.unit("meter"),), # -> Unit('meter') | ||
(u.Quantity(1, "m"),), # -> Unit('meter') | ||
(2,), | ||
], | ||
) | ||
@pytest.mark.benchmark(group="units", warmup=False) | ||
|
||
@pytest.mark.parametrize("args", args, ids=str) | ||
@pytest.mark.benchmark(group="units", warmup=False, max_time=1.0) | ||
def test_unit_of(args): | ||
"""Test calling `unxt.unit_of`.""" | ||
_ = u.unit_of(*args) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"args", | ||
[ | ||
(u.Quantity(1, "m"),), # -> Unit('meter') | ||
], | ||
) | ||
@pytest.mark.benchmark(group="units", warmup=False) | ||
def test_unit_of_jit_compile(func_unit_of_length, args): | ||
@pytest.mark.parametrize("args", args, ids=str) | ||
@pytest.mark.benchmark(group="units", warmup=False, max_time=1.0) | ||
def test_unit_of_jit_compile(func_unit_of, args): | ||
"""Test the speed of jitting a function.""" | ||
_ = jax.jit(func_unit_of_length).lower(*args).compile() | ||
_ = func_unit_of.lower(*args).compile() | ||
|
||
|
||
@pytest.mark.parametrize("args", args, ids=str) | ||
@pytest.mark.benchmark(group="units", warmup=True, max_time=1.0) | ||
def test_unit_of_execute(func_unit_of, args): | ||
"""Test the speed of calling the function.""" | ||
_ = jax.block_until_ready(func_unit_of(*args)) |
Oops, something went wrong.