From maintainers-request at octave dot org Sun Jan 30 01:57:01 2005 Subject: Re: min function very slow? From: "John W. Eaton" To: Daniel J Sebald Cc: maintainers at octave dot org Date: Sun, 30 Jan 2005 01:55:39 -0600 On 30-Jan-2005, Daniel J Sebald wrote: | On second thought, your hypothesis seems correct. rand() and randn() | are similar to max/min, being in the same file. I rewrote the function | with rand/randn and got similar behavior: | | octave:1> [loopt, randt, randnt] = rrt(10000) | loopt = 0.10696 | randt = 0.36079 | randnt = 0.35501 | octave:2> [loopt, randt, randnt] = rrt(10000) | loopt = 0.10461 | randt = 0.34843 | randnt = 7.3243 If you get results like this, then I suspect your function is still computing the time differences incorrectly. Try something like function [looptime,maxtime,mintime]=mmt(N_loop) t = zeros(4,1); k=1 t(k++) = cputime(); for i=1:N_loop j = i; end t(k++) = cputime(); for i=1:N_loop j = min(i); end t(k++) = cputime(); for i=1:N_loop j = max(i); end t(k++) = cputime(); x = diff (t); looptime = x(1); maxtime = x(2); mintime = x(3); endfunction Your original function used toc() incorrectly. It always returns the time since the last call to tic(). jwe