Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function bench_median ()
- rand ("state", 0);
- sizes = [1e4, 1e5, 5e5, 1e6];
- nreps = 5; # Number of repetitions for timing
- printf ("\nVector median\n");
- for n = sizes
- x = rand (n, 1);
- tic;
- for r = 1:nreps
- median (x);
- endfor
- t = toc / nreps;
- printf ("n = %d : %.6f s\n", n, t);
- endfor
- printf ("\nMatrix column median\n");
- for n = sizes
- x = rand (n, 100);
- tic;
- for r = 1:nreps
- median (x, 1);
- endfor
- t = toc / nreps;
- printf ("n = %d x 100 : %.6f s\n", n, t);
- endfor
- printf ("\nWith NaNs (omitnan)\n");
- for n = sizes
- x = rand (n, 100);
- x(1:10:end) = NaN;
- tic;
- for r = 1:nreps
- median (x, 1, "omitnan");
- endfor
- t = toc / nreps;
- printf ("n = %d x 100 : %.6f s\n", n, t);
- endfor
- end
Advertisement
Add Comment
Please, Sign In to add comment