1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-27 02:08:54 +00:00

use zeros for benchmarks

This commit is contained in:
Thomas Waldmann 2021-01-14 20:19:10 +01:00
parent be257728ca
commit e41dc6e96f
2 changed files with 5 additions and 2 deletions

View file

@ -453,9 +453,10 @@ def measurement_run(repo, path):
def test_files(path, count, size, random): def test_files(path, count, size, random):
path = os.path.join(path, 'borg-test-data') path = os.path.join(path, 'borg-test-data')
os.makedirs(path) os.makedirs(path)
z_buff = None if random else memoryview(zeros)[:size] if size <= len(zeros) else b'\0' * size
for i in range(count): for i in range(count):
fname = os.path.join(path, 'file_%d' % i) fname = os.path.join(path, 'file_%d' % i)
data = b'\0' * size if not random else os.urandom(size) data = z_buff if not random else os.urandom(size)
with SyncFile(fname, binary=True) as fd: # used for posix_fadvise's sake with SyncFile(fname, binary=True) as fd: # used for posix_fadvise's sake
fd.write(data) fd.write(data)
yield path yield path

View file

@ -11,6 +11,7 @@
import pytest import pytest
from .archiver import changedir, cmd from .archiver import changedir, cmd
from ..constants import zeros
@pytest.fixture @pytest.fixture
@ -34,12 +35,13 @@ def repo(request, cmd, repo_url):
@pytest.fixture(scope='session', params=["zeros", "random"]) @pytest.fixture(scope='session', params=["zeros", "random"])
def testdata(request, tmpdir_factory): def testdata(request, tmpdir_factory):
count, size = 10, 1000*1000 count, size = 10, 1000*1000
assert size <= len(zeros)
p = tmpdir_factory.mktemp('data') p = tmpdir_factory.mktemp('data')
data_type = request.param data_type = request.param
if data_type == 'zeros': if data_type == 'zeros':
# do not use a binary zero (\0) to avoid sparse detection # do not use a binary zero (\0) to avoid sparse detection
def data(size): def data(size):
return b'0' * size return memoryview(zeros)[:size]
elif data_type == 'random': elif data_type == 'random':
def data(size): def data(size):
return os.urandom(size) return os.urandom(size)