-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This will be useful for when wanting to run small benchmarks. It will also allow us to remove a small snippet of code we previously had in the tests. Signed-off-by: Rodrigo Tobar <rtobar@icrar.org>
- Loading branch information
Showing
4 changed files
with
59 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import argparse | ||
import time | ||
|
||
from ._crc32c import crc32c | ||
|
||
DEFAULT_SIZE = 100 * 1024 * 1024 | ||
DEFAULT_ITERATIONS = 10 | ||
|
||
|
||
def run(size: int, iterations: int) -> float: | ||
data = b" " * size | ||
start = time.monotonic() | ||
[crc32c(data) for _ in range(iterations)] | ||
end = time.monotonic() | ||
return end - start | ||
|
||
|
||
def main() -> None: | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"-s", | ||
"--size", | ||
type=int, | ||
help=f"Amount of bytes to checksum, defaults to {DEFAULT_SIZE}", | ||
default=DEFAULT_SIZE, | ||
) | ||
parser.add_argument( | ||
"-i", | ||
"--iterations", | ||
type=int, | ||
help=f"Number of times the checksum should we run over the data, defaults to {DEFAULT_ITERATIONS}", | ||
default=DEFAULT_ITERATIONS, | ||
) | ||
|
||
options = parser.parse_args() | ||
duration = run(options.size, options.iterations) | ||
print( | ||
f"crc32c ran at {options.size * options.iterations / duration / 1024 / 1024 / 1024:.3f} [GB/s]" | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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,10 @@ | ||
import subprocess | ||
import sys | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.calculates_crc32c | ||
def test_benchmark() -> None: | ||
out = subprocess.check_output([sys.executable, "-m", "crc32c.benchmark"]) | ||
assert b"crc32c ran at" in out |