[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Distinguishing Octave from Matlab
From: |
John W. Eaton |
Subject: |
Re: Distinguishing Octave from Matlab |
Date: |
Thu, 19 Feb 2009 13:01:16 -0500 |
On 19-Feb-2009, José Luis García Pallero wrote:
| I usually use a function like this:
|
| function [inOctave] = in_octave()
| try
| OCTAVE_VERSION;
| inOctave = 1;
| catch
| inOctave = 0;
| end
|
| What is the difference with the persistent inout =
| exist("OCTAVE_VERSION","builtin") != 0; version?
| Is the evaluation of exist() function faster than OCTAVE_VERSION and
| try-catch statement?
The idea with the persistent variable is that you only initialize it
once.
On my system, your try-catch solution is slightly faster (100,000
calls in a for loop):
try-catch: 1.54 seconds
persistent: 1.60 seconds
If you could write it like this:
function retval = inoctave ()
persistent inout = exist ('OCTAVE_VERSION', 'builtin') ~= 0;
retval = inout;
end
in Matlab, then it would be faster still, as you can avoid the if
statement and the call to isempty. This version takes about .98
seconds on my system for the same 100,000 trips through the for loop.
But really, how many times do you have to call this function? If it
is in a loop, then maybe you should find a way to move the call out of
the loop. Call the function and set a variable, and then check the
variable instead of calling the function repeatedly.
jwe