octave-maintainers
[Top][All Lists]
Advanced

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

cellfun benchmarks


From: Rik
Subject: cellfun benchmarks
Date: Thu, 04 Aug 2011 13:30:02 -0700

8/4/11

All,

After speeding up strtrim() 15X by replacing the cellfun() call with a call
to regexprep() I have been looking at the behavior of cellfun.  I created a
simple benchmark where I take an array of random values (1000 x 1000) and
calculate the sine of each element in different manners.  The attached
script bm_cellfun.m shows the actual code.

The results are:

##################################################
vectorized version
0.064057

for loop
23.000

arrayfun
1.4118

cellfun
1.2382

cellfun w/uniform output
1.3266

-------------------------

for loop w/mysin m-file
61.254

arrayfun w/mysin m-file
28.516

cellfun w/mysin m-file
27.809

-------------------------

cellfun w/mysin2 subfunction
27.414

-------------------------

cellfun w/mysin3 nested function (coerced to subfunction)
27.414

-------------------------

cellfun w/anonymous function
1.4005

-------------------------

cellfun w/inline function
18.023

##################################################

As expected, just calling sin() directly on an array is really fast.  In
fact its 19.33 times faster than cellfun (@sin, x).  I was hoping for
something more in the range of 3X-5X faster, but this is still probably
acceptable.  Where cellfun really breaks down is when the function to be
applied to each element is defined in an m-file.  At this point cellfun is
over 400X slower.  It is similarly bad when an inline() function is used.
Does anyone with experience with the guts of Octave have an idea on this?
Are we re-parsing the m-file every time through the loop?  Are we checking
the timestamp to see if the file has been modified every time through the loop?

Cheers,
Rik


Attachment: bm_cellfun.m
Description: Text Data

Attachment: mysin.m
Description: Text Data


reply via email to

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