-
-
Notifications
You must be signed in to change notification settings - Fork 734
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add benchmarking code for crc32 code / libs
- Loading branch information
1 parent
27f0f37
commit 93069c5
Showing
1 changed file
with
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# benchmark deflate crc32 against zlib crc32 | ||
# note: we have other tests for correctness of the result, so we do not check it here. | ||
|
||
try: | ||
import deflate | ||
except ImportError: | ||
deflate = None | ||
|
||
import pytest | ||
import zlib | ||
|
||
from borg.algorithms.checksums import crc32_slice_by_8 as borg_crc32_slice8 | ||
from borg.algorithms.checksums import crc32_clmul as borg_crc32_clmul | ||
from borg.algorithms.checksums import have_clmul | ||
|
||
import os | ||
|
||
data = os.urandom(10 * 1000000) | ||
|
||
CORRECT = zlib.crc32(data) | ||
|
||
|
||
def test_zlib_crc32(benchmark): | ||
@benchmark | ||
def result(): | ||
return zlib.crc32(data) | ||
|
||
assert result == CORRECT | ||
|
||
|
||
@pytest.mark.skipif(not hasattr(deflate, 'crc32'), reason="deflate.crc32 not available") | ||
def test_deflate_crc32(benchmark): | ||
@benchmark | ||
def result(): | ||
return deflate.crc32(data) | ||
|
||
assert result == CORRECT | ||
|
||
|
||
def test_borg_crc32_slice8(benchmark): | ||
@benchmark | ||
def result(): | ||
return borg_crc32_slice8(data) | ||
|
||
assert result == CORRECT | ||
|
||
@pytest.mark.skipif(not have_clmul, reason="clmul not detected") | ||
def test_borg_crc32_clmul(benchmark): | ||
@benchmark | ||
def result(): | ||
return borg_crc32_clmul(data) | ||
|
||
assert result == CORRECT |