Skip to content

Commit

Permalink
tests: add benchmarking code for crc32 code / libs
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasWaldmann committed Mar 2, 2022
1 parent 27f0f37 commit 93069c5
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/borg/testsuite/test_crc32_bench.py
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

0 comments on commit 93069c5

Please sign in to comment.