Skip to content

Commit

Permalink
add speed benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Sep 20, 2022
1 parent 84892ca commit 6f1e437
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
40 changes: 40 additions & 0 deletions example/zmat_speedbench.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
function zmat_speedbench(varargin)
%
% Usage:
% zmat_speedbench
% zmat_speedbench('nthread', 8, 'shuffle', 1, 'typesize', 8)
%
% Author: Qianqian Fang <q.fang at neu.edu>
%

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(:));
2 changes: 1 addition & 1 deletion src/zmatlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand Down
7 changes: 6 additions & 1 deletion zmat.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6f1e437

Please sign in to comment.