[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
NaN-toolbox much faster now
From: |
Alois Schlögl |
Subject: |
NaN-toolbox much faster now |
Date: |
Thu, 12 Mar 2009 17:13:35 +0100 |
User-agent: |
Thunderbird 2.0.0.19 (X11/20090105) |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
The following improvements have been included in the NaN-toolbox.
- - sumskipnan_mex.mex has been optimized for speed (minimizing cache
missing, reducing loop overhead)
- - a flag is set if some NaN occures in the data. The flag can be checked
(and reset) with function FLAG_NANS_OCCURED(). This enables a flexible
control on checks for NaN. (You can check after every call, or only at
the end of your script).
- - the performance of var, std, and meansq has been improved.
A performance between the NaN-toolbox and corresponding standard octave
functions (see script below) show the following results (time in [s]):
with NaN-tb w/o NaN-tb ratio
0.25884 3.56726 13.78183 mean(x,1)/nanmean(x,1)
0.36784 3.32899 9.05020 mean(x,2)/nanmean(x,2)
0.30019 6.62467 22.06789 std(x,0,1)
0.40114 2.23262 5.56561 std(x,0,2)
0.28681 6.40276 22.32407 var(x,0,1)
0.40269 2.18056 5.41505 var(x,0,2)
0.28175 4.05612 14.39598 meansq(x,1)
0.40703 4.19346 10.30248 meansq(x,2)
0.25930 0.19884 0.76683 sumskipnan(x,1)/sum(x,1)
0.30624 0.24179 0.78955 sumskipnan(x,2)/sum(x,2)
A performance improvement by factors as high as 22 can be seen, and
sumskipnan() is only about 25% slower than sum().
Of course, sumskipnan could also improve the speed of functions like
nanmean, nanstd, etc. Maybe you want to consider including sumskipnan in
standard octave.
Cheers,
Alois
======== script of for the performance test ===
The machine has 4 GB of RAM (no swapping took place) AMD64, Ubuntu 8.
x=randn(1e4); %%!!! 800 MBytes
%% add path to .../octave-forge/extra/NaN/src
mex .../octave-forge/extra/NaN/src/sumskipnan_mex.cpp
%% add path to .../octave-forge/extra/NaN/inst
k=1;
t=cputime();tic; m = mean(x,1); T(k,1)=toc;V(k,1)=cputime()-t;
t=cputime();tic; m = mean(x,2); T(k,2)=toc;V(k,2)=cputime()-t;
t=cputime();tic; m = std(x,0,1); T(k,3)=toc;V(k,3)=cputime()-t;
t=cputime();tic; m = std(x,0,2); T(k,4)=toc;V(k,4)=cputime()-t;
t=cputime();tic; m = var(x,0,1); T(k,5)=toc;V(k,5)=cputime()-t;
t=cputime();tic; m = var(x,0,2); T(k,6)=toc;V(k,6)=cputime()-t;
t=cputime();tic; m = meansq(x,1); T(k,7)=toc;V(k,7)=cputime()-t;
t=cputime();tic; m = meansq(x,2); T(k,8)=toc;V(k,8)=cputime()-t;
t=cputime();tic; m = sumskipnan(x,1); T(k,9)=toc;V(k,9)=cputime()-t;
t=cputime();tic; m = sumskipnan(x,2); T(k,10)=toc;V(k,10)=cputime()-t;
%% remove path to .../octave-forge/extra/NaN/src
%% remove path to .../octave-forge/extra/NaN/inst
k = 2;
t=cputime();tic; n=sum(~isnan(x),1);x(isnan(x))=0;
m = sum(x,1)./n; T(k,1)=toc;V(k,1)=cputime()-t; %% nanmean
t=cputime();tic; n=sum(~isnan(x),2);x(isnan(x))=0;
m = sum(x,2)./n; T(k,2)=toc;V(k,2)=cputime()-t; %% nanmean
t=cputime();tic; m = std(x,0,1); T(k,3)=toc;V(k,3)=cputime()-t;
t=cputime();tic; m = std(x,0,2); T(k,4)=toc;V(k,4)=cputime()-t;
t=cputime();tic; m = var(x,0,1); T(k,5)=toc;V(k,5)=cputime()-t;
t=cputime();tic; m = var(x,0,2); T(k,6)=toc;V(k,6)=cputime()-t;
t=cputime();tic; m = meansq(x,1); T(k,7)=toc;V(k,7)=cputime()-t;
t=cputime();tic; m = meansq(x,2); T(k,8)=toc;V(k,8)=cputime()-t;
t=cputime();tic; m = sum(x,1); T(k,9)=toc;V(k,9)=cputime()-t;
t=cputime();tic; m = sum(x,2); T(k,10)=toc;V(k,10)=cputime()-t;
[V',V(2,:)'./V(1,:)']
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkm5NKsACgkQzSlbmAlvEIgxjwCgrrxMU6VFaJiibU7Il8P4rhEl
ZD8An2Rs5a/3EBv3dYy+SmrWZjo0uxk/
=YOw4
-----END PGP SIGNATURE-----
- NaN-toolbox much faster now,
Alois Schlögl <=
- Re: NaN-toolbox much faster now, Jaroslav Hajek, 2009/03/14
- Re: NaN-toolbox much faster now, Alois Schlögl, 2009/03/16
- Re: NaN-toolbox much faster now, Jaroslav Hajek, 2009/03/16
- Re: NaN-toolbox much faster now, Alois Schlögl, 2009/03/17
- Re: NaN-toolbox much faster now, Jaroslav Hajek, 2009/03/17
- Re: NaN-toolbox much faster now, Alois Schlögl, 2009/03/17
- Re: NaN-toolbox much faster now, John W. Eaton, 2009/03/17
- Re: NaN-toolbox much faster now, Alois Schlögl, 2009/03/18
- Re: NaN-toolbox much faster now, Jason Riedy, 2009/03/18
- Re: NaN-toolbox much faster now, Alois Schlögl, 2009/03/19