[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: min function very slow?

From: John W. Eaton
Subject: Re: min function very slow?
Date: Sun, 30 Jan 2005 01:55:39 -0600

On 30-Jan-2005, Daniel J Sebald <address@hidden> 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);
    t(k++) = cputime();
    for i=1:N_loop
      j = i;
    t(k++) = cputime();
    for i=1:N_loop
      j = min(i);
    t(k++) = cputime();
    for i=1:N_loop
      j = max(i);
    t(k++) = cputime();
    x = diff (t);
    looptime = x(1);
    maxtime = x(2);
    mintime = x(3);

Your original function used toc() incorrectly.  It always returns the
time since the last call to tic().


reply via email to

[Prev in Thread] Current Thread [Next in Thread]