help-octave
[Top][All Lists]
Advanced

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

slow for-loops


From: Stef Pillaert
Subject: slow for-loops
Date: Mon, 30 Mar 1998 13:08:23 +0200

Hello,

I translate a lot of my functions to .oct files, and one of the main
reasons is that I do a lot of (simple, short) loops.

A sample .m-file like:

function retval=test_lus(times)
 for i=1:times
 endfor
 disp ("m-file done");
 retval=1;
endfunction

takes a LOT more time then it's .oct-counterpart:

#include <octave/oct.h>
#include "iostream.h"

DEFUN_DLD (test_lus_oct,args,,
"")
 {

  int times = int(args(0).double_value());
  for (int i=0 ; i < times ; i++) {}
  cout << "oct-file done";
  return octave_value(1);
 }

The second function runs on my system about 500 times faster!!(I set
times=1000000)

Is this behaviour normal, and if so, is there an alternative (without the
need of translating everything to .oct-files, because this is a lot more
work then writing simple .m-files...).

Thanks,

Stef.




reply via email to

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