From 6f1e4373d646bb663338291b4a52c496048652ca Mon Sep 17 00:00:00 2001 From: Qianqian Fang Date: Tue, 20 Sep 2022 09:40:48 -0400 Subject: [PATCH] add speed benchmark --- example/zmat_speedbench.m | 40 +++++++++++++++++++++++++++++++++++++++ src/zmatlib.c | 2 +- zmat.m | 7 ++++++- 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 example/zmat_speedbench.m diff --git a/example/zmat_speedbench.m b/example/zmat_speedbench.m new file mode 100644 index 0000000..b70a546 --- /dev/null +++ b/example/zmat_speedbench.m @@ -0,0 +1,40 @@ +function zmat_speedbench(varargin) +% +% Usage: +% zmat_speedbench +% zmat_speedbench('nthread', 8, 'shuffle', 1, 'typesize', 8) +% +% Author: Qianqian Fang +% + +codecs={'zlib', 'gzip', 'lzma', 'lz4', 'lz4hc', 'zstd', ... + 'blosc2blosclz', 'blosc2lz4', 'blosc2lz4hc', ... + 'blosc2zlib', 'blosc2zstd'}; + +runbench('1. eye(2000)', eye(2000), codecs, varargin{:}); +runbench('2. rand(2000)', rand(2000), codecs, varargin{:}); +runbench('3. magic(2000)', uint32(magic(2000)), codecs, varargin{:}); +runbench('4. peaks(2000)', single(peaks(2000)), codecs, varargin{:}); + +%---------------------------------------------------------- +function runbench(name, mat, codecs, varargin) +disp(name) +res=cellfun(@(x) benchmark(x, mat, varargin{:}), codecs, 'UniformOutput', false); +if(exist('OCTAVE_VERSION','builtin')) + disp(res) +else + res=sortrows(struct2table(cell2mat(res)),'total') +end + +%---------------------------------------------------------- +function res=benchmark(codec, x, varargin) +tic; +[a,info]=zmat(x, 1, codec, varargin{:}); +res.codec=codec; +res.save=toc; +res.size=uint32(numel(a)); +tic; +b=zmat(a, info); +res.load=toc; +res.total=res.load+res.save; +res.sum=sum(b(:)); diff --git a/src/zmatlib.c b/src/zmatlib.c index 0b98ea7..b227c7a 100644 --- a/src/zmatlib.c +++ b/src/zmatlib.c @@ -450,7 +450,7 @@ int zmat_run(const size_t inputsize, unsigned char* inputstr, size_t* outputsize return *ret; } - while ((*ret = blosc1_decompress((const char*)inputstr, (char*)(*outputbuf), *outputsize)) <= 0 && count <= 10) { + while ((*ret = blosc1_decompress((const char*)inputstr, (char*)(*outputbuf), *outputsize)) <= 0 && count <= 16) { *outputsize = (inputsize << count); if (!(*outputbuf = (unsigned char*)realloc(*outputbuf, *outputsize))) { diff --git a/zmat.m b/zmat.m index 9ede51d..9e67029 100644 --- a/zmat.m +++ b/zmat.m @@ -117,8 +117,13 @@ opt=cell2struct(varargin(5:2:end), varargin(4:2:end), 2); end +shuffle=0; +if(strfind(zipmethod,'blosc2')) + shuffle=1; +end + nthread=getoption('nthread', 1, opt); -shuffle=getoption('shuffle', 1, opt); +shuffle=getoption('shuffle', shuffle, opt); typesize=getoption('typesize', typesize, opt); iscompress = round(iscompress);