octave-maintainers
[Top][All Lists]
Advanced

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

Re: Testing for function handles


From: Juan Pablo Carbajal
Subject: Re: Testing for function handles
Date: Wed, 9 Nov 2011 11:32:28 +0100

On Wed, Nov 9, 2011 at 11:01 AM, Richard <address@hidden> wrote:
> On 09/11/2011 08:18, Dr. Alexander Klein wrote:
>>
>> Good morning,
>>
>> is there any preferred way to check whether a given parameter or variable
>> contains a function handle?
>>
>> I find myself strcmp'ing the result of typeinfo quite often, but this is
>> really clumsy. Then again, ishandle only checks for graphics handles ...
>>
>> Best regards,
>>
>>        Alex
>>
>
> if it is octave code you can use the 'isa' function e.g.
>
> isa(@sin, 'function_handle')
>
> but maybe I'm misunderstanding and you mean in the C++ sources or something.
>
> Richard
>
> --
> The University of Edinburgh is a charitable body, registered in
> Scotland, with registration number SC005336.
>
>

Checking
f = @(x)x;
n=5e4;
t0=cputime;
for i=1:n
  strcmp(typeinfo(f),'function_handle');
end
t=cputime-t0

t0=cputime;
for i=1:n
  isa(f,'function_handle');
end
t=cputime-t0

I get
t =  1.0521
for strcmp
t =  5.0083
for isa

Is the benchmark correct?

-- 
M. Sc. Juan Pablo Carbajal
-----
PhD Student
University of Zürich
http://ailab.ifi.uzh.ch/carbajal/


reply via email to

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