-
Notifications
You must be signed in to change notification settings - Fork 626
Add Python version of the basic benchmarks #4411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9c9d4ed
33a9877
0f84030
6fb94f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -130,3 +130,4 @@ python-packages = ["rerun_sdk/rerun"] | |
| filterwarnings = """ | ||
| error | ||
| """ | ||
| norecursedirs = ".* venv* target* build" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import dataclasses | ||
|
|
||
| import numpy as np | ||
|
|
||
| MAX_INT64 = 2**63 - 1 | ||
| MAX_INT32 = 2**31 - 1 | ||
|
|
||
|
|
||
| @dataclasses.dataclass | ||
| class Point3DInput: | ||
| positions: np.ndarray | ||
| colors: np.ndarray | ||
| radii: np.ndarray | ||
| label: str = "some label" | ||
|
|
||
| @classmethod | ||
| def prepare(cls, seed: int, num_points: int): | ||
| rng = np.random.default_rng(seed=seed) | ||
|
|
||
| return cls( | ||
| positions=rng.integers(0, MAX_INT64, (num_points, 3)).astype(dtype=np.float32), | ||
| colors=rng.integers(0, MAX_INT32, num_points, dtype=np.uint32), | ||
| radii=rng.integers(0, MAX_INT64, num_points).astype(dtype=np.float32), | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| """Python logging benchmarks. Use `just py-bench` to run.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import numpy as np | ||
| import pytest | ||
| import rerun as rr | ||
|
|
||
| from . import Point3DInput | ||
|
|
||
|
|
||
| def log_points3d_large_batch(data: Point3DInput): | ||
| # create a new, empty memory sink for the current recording | ||
| rr.memory_recording() | ||
|
|
||
| rr.log( | ||
| "large_batch", | ||
| rr.Points3D(positions=data.positions, colors=data.colors, radii=data.radii, labels=data.label), | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("num_points", [50_000_000]) | ||
| def test_bench_points3d_large_batch(benchmark, num_points): | ||
| rr.init("rerun_example_benchmark_points3d_large_batch") | ||
| data = Point3DInput.prepare(42, num_points) | ||
| benchmark(log_points3d_large_batch, data) | ||
|
|
||
|
|
||
| def log_points3d_many_individual(data: Point3DInput): | ||
| # create a new, empty memory sink for the current recording | ||
| rr.memory_recording() | ||
|
|
||
| for i in range(data.positions.shape[0]): | ||
| rr.log( | ||
| "single_point", | ||
| rr.Points3D(positions=data.positions[i], colors=data.colors[i], radii=data.radii[i]), | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("num_points", [100_000]) | ||
| def test_bench_points3d_many_individual(benchmark, num_points): | ||
| rr.init("rerun_example_benchmark_points3d_many_individual") | ||
| data = Point3DInput.prepare(1337, num_points) | ||
| benchmark(log_points3d_many_individual, data) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there anyway to specify that the throughput of this benchmark is 100k per iteration, so that the stats make sense?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call. I've factored parametrisation in a better way that's explicit in the test name (and extensible if we want more test cases in the future). Which reminds me to put a note that the num_point for |
||
|
|
||
|
|
||
| def log_image(image: np.ndarray, num_log_calls): | ||
| # create a new, empty memory sink for the current recording | ||
| rr.memory_recording() | ||
|
|
||
| for i in range(num_log_calls): | ||
| rr.log("test_image", rr.Tensor(image)) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ["image_dimension", "image_channels", "num_log_calls"], | ||
| [pytest.param(16_384, 4, 4, id="16384^2px-4channels-4calls")], | ||
| ) | ||
| def test_bench_image(benchmark, image_dimension, image_channels, num_log_calls): | ||
| rr.init("rerun_example_benchmark_image") | ||
|
|
||
| image = np.zeros((image_dimension, image_dimension, image_channels), dtype=np.uint8) | ||
| benchmark(log_image, image, num_log_calls) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| -r test_api/requirements.txt | ||
| -r nv12image/requirements.txt | ||
| pytest-benchmark |
Uh oh!
There was an error while loading. Please reload this page.