<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
> <channel><title>Comments on: cellfun &#8211; undocumented performance boost</title> <atom:link href="http://undocumentedmatlab.com/blog/cellfun-undocumented-performance-boost/feed/" rel="self" type="application/rss+xml" /><link>http://undocumentedmatlab.com/blog/cellfun-undocumented-performance-boost/</link> <description>Charting Matlab's unsupported hidden underbelly</description> <lastBuildDate>Thu, 09 Feb 2012 09:23:08 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.1.1</generator> <item><title>By: Jordi Gutiérrez Hermoso</title><link>http://undocumentedmatlab.com/blog/cellfun-undocumented-performance-boost/#comment-63587</link> <dc:creator>Jordi Gutiérrez Hermoso</dc:creator> <pubDate>Tue, 29 Nov 2011 16:30:38 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=260#comment-63587</guid> <description>I looked at your example, and I noticed that in Octave we hadn&#039;t quite optimised this as much as possible. I went ahead and committed a change to fix this:http://hg.savannah.gnu.org/hgweb/octave/rev/cf8cd43cdeb3On my laptop with Intel Core 2 Duo @ 2.20G, I see the following:&lt;pre lang=&quot;matlab&quot;&gt;
octave:1&gt; c = mat2cell(1:1e6,1,repmat(1,1,1e6));
octave:2&gt; tic, d=cellfun(&#039;isempty&#039;,c); toc
Elapsed time is 0.0171831 seconds.
octave:3&gt; tic, d=cellfun(&#039;isempty&#039;,c); toc
Elapsed time is 0.0182698 seconds.
octave:4&gt; tic, d=cellfun(&#039;isempty&#039;,c); toc
Elapsed time is 0.0223808 seconds.octave:5&gt; tic, d=cellfun(@isempty,c); toc
Elapsed time is 0.0193319 seconds.
octave:6&gt; tic, d=cellfun(@isempty,c); toc
Elapsed time is 0.01612 seconds.
octave:7&gt; tic, d=cellfun(@isempty,c); toc
Elapsed time is 0.019449 seconds.
&lt;/pre&gt;This should be part of our 3.6 release that should happen very soon!Sadly, your preferred method of calling cellfun cannot be easily optimised:&lt;pre lang=&quot;matlab&quot;&gt;
octave:8&gt; tic, d=cellfun(@(x) isempty(x),c); toc
Elapsed time is 0.924903 seconds.
octave:9&gt; tic, d=cellfun(@(x) isempty(x),c); toc
Elapsed time is 0.873197 seconds.
octave:10&gt; tic, d=cellfun(@(x) isempty(x),c); toc
Elapsed time is 0.875425 seconds.
&lt;/pre&gt;Note that Octave still is single-threaded, so this does not benefit from any parallelisation right now. There&#039;s work to build parallelisation into Octave, so perhaps we can see more dramatic speedups in the future.</description> <content:encoded><![CDATA[<p>I looked at your example, and I noticed that in Octave we hadn&#8217;t quite optimised this as much as possible. I went ahead and committed a change to fix this:</p><p><a
href="http://hg.savannah.gnu.org/hgweb/octave/rev/cf8cd43cdeb3" rel="nofollow">http://hg.savannah.gnu.org/hgweb/octave/rev/cf8cd43cdeb3</a></p><p>On my laptop with Intel Core 2 Duo @ 2.20G, I see the following:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">octave<span style="color: #F0F;">:</span><span style="color: #33f;">1</span>&gt; c = mat2cell<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #F0F;">:</span>1e6,<span style="color: #33f;">1</span>,<span style="color: #0000FF;">repmat</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,1e6<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
octave<span style="color: #F0F;">:</span><span style="color: #33f;">2</span>&gt; <span style="color: #0000FF;">tic</span>, d=<span style="color: #0000FF;">cellfun</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'isempty'</span>,c<span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">toc</span>
Elapsed time <span style="color: #0000FF;">is</span> <span style="color: #33f;">0.0171831</span> seconds.
<span style="">octave</span><span style="color: #F0F;">:</span><span style="color: #33f;">3</span>&gt; <span style="color: #0000FF;">tic</span>, d=<span style="color: #0000FF;">cellfun</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'isempty'</span>,c<span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">toc</span>
Elapsed time <span style="color: #0000FF;">is</span> <span style="color: #33f;">0.0182698</span> seconds.
<span style="">octave</span><span style="color: #F0F;">:</span><span style="color: #33f;">4</span>&gt; <span style="color: #0000FF;">tic</span>, d=<span style="color: #0000FF;">cellfun</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'isempty'</span>,c<span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">toc</span>
Elapsed time <span style="color: #0000FF;">is</span> <span style="color: #33f;">0.0223808</span> seconds.
&nbsp;
<span style="">octave</span><span style="color: #F0F;">:</span><span style="color: #33f;">5</span>&gt; <span style="color: #0000FF;">tic</span>, d=<span style="color: #0000FF;">cellfun</span><span style="color: #080;">&#40;</span>@<span style="color: #0000FF;">isempty</span>,c<span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">toc</span>
Elapsed time <span style="color: #0000FF;">is</span> <span style="color: #33f;">0.0193319</span> seconds.
<span style="">octave</span><span style="color: #F0F;">:</span><span style="color: #33f;">6</span>&gt; <span style="color: #0000FF;">tic</span>, d=<span style="color: #0000FF;">cellfun</span><span style="color: #080;">&#40;</span>@<span style="color: #0000FF;">isempty</span>,c<span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">toc</span>
Elapsed time <span style="color: #0000FF;">is</span> <span style="color: #33f;">0.01612</span> seconds.
<span style="">octave</span><span style="color: #F0F;">:</span><span style="color: #33f;">7</span>&gt; <span style="color: #0000FF;">tic</span>, d=<span style="color: #0000FF;">cellfun</span><span style="color: #080;">&#40;</span>@<span style="color: #0000FF;">isempty</span>,c<span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">toc</span>
Elapsed time <span style="color: #0000FF;">is</span> <span style="color: #33f;">0.019449</span> seconds.</pre></div></div><p>This should be part of our 3.6 release that should happen very soon!</p><p>Sadly, your preferred method of calling cellfun cannot be easily optimised:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">octave<span style="color: #F0F;">:</span><span style="color: #33f;">8</span>&gt; <span style="color: #0000FF;">tic</span>, d=<span style="color: #0000FF;">cellfun</span><span style="color: #080;">&#40;</span>@<span style="color: #080;">&#40;</span>x<span style="color: #080;">&#41;</span> <span style="color: #0000FF;">isempty</span><span style="color: #080;">&#40;</span>x<span style="color: #080;">&#41;</span>,c<span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">toc</span>
Elapsed time <span style="color: #0000FF;">is</span> <span style="color: #33f;">0.924903</span> seconds.
<span style="">octave</span><span style="color: #F0F;">:</span><span style="color: #33f;">9</span>&gt; <span style="color: #0000FF;">tic</span>, d=<span style="color: #0000FF;">cellfun</span><span style="color: #080;">&#40;</span>@<span style="color: #080;">&#40;</span>x<span style="color: #080;">&#41;</span> <span style="color: #0000FF;">isempty</span><span style="color: #080;">&#40;</span>x<span style="color: #080;">&#41;</span>,c<span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">toc</span>
Elapsed time <span style="color: #0000FF;">is</span> <span style="color: #33f;">0.873197</span> seconds.
<span style="">octave</span><span style="color: #F0F;">:</span><span style="color: #33f;">10</span>&gt; <span style="color: #0000FF;">tic</span>, d=<span style="color: #0000FF;">cellfun</span><span style="color: #080;">&#40;</span>@<span style="color: #080;">&#40;</span>x<span style="color: #080;">&#41;</span> <span style="color: #0000FF;">isempty</span><span style="color: #080;">&#40;</span>x<span style="color: #080;">&#41;</span>,c<span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">toc</span>
Elapsed time <span style="color: #0000FF;">is</span> <span style="color: #33f;">0.875425</span> seconds.</pre></div></div><p>Note that Octave still is single-threaded, so this does not benefit from any parallelisation right now. There&#8217;s work to build parallelisation into Octave, so perhaps we can see more dramatic speedups in the future.</p> ]]></content:encoded> </item> <item><title>By: Yair Altman</title><link>http://undocumentedmatlab.com/blog/cellfun-undocumented-performance-boost/#comment-63578</link> <dc:creator>Yair Altman</dc:creator> <pubDate>Tue, 29 Nov 2011 15:05:23 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=260#comment-63578</guid> <description>@Jordi - thanks. If you have any other comparisons to Octave for any of the other articles here, please do post a comment.</description> <content:encoded><![CDATA[<p>@Jordi &#8211; thanks. If you have any other comparisons to Octave for any of the other articles here, please do post a comment.</p> ]]></content:encoded> </item> <item><title>By: Jordi Gutiérrez Hermoso</title><link>http://undocumentedmatlab.com/blog/cellfun-undocumented-performance-boost/#comment-63576</link> <dc:creator>Jordi Gutiérrez Hermoso</dc:creator> <pubDate>Tue, 29 Nov 2011 14:59:38 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=260#comment-63576</guid> <description>This is very interesting. Our independent implementation of cellfun in Octave actually behaves very similarly! However, I did optimise it to check function handles for built-in string cases.We have a thread about it:http://octave.1599824.n4.nabble.com/More-cellfun-related-benchmarks-td3724314.html</description> <content:encoded><![CDATA[<p>This is very interesting. Our independent implementation of cellfun in Octave actually behaves very similarly! However, I did optimise it to check function handles for built-in string cases.</p><p>We have a thread about it:</p><p> <a
href="http://octave.1599824.n4.nabble.com/More-cellfun-related-benchmarks-td3724314.html" rel="nofollow">http://octave.1599824.n4.nabble.com/More-cellfun-related-benchmarks-td3724314.html</a></p> ]]></content:encoded> </item> <item><title>By: tdc</title><link>http://undocumentedmatlab.com/blog/cellfun-undocumented-performance-boost/#comment-62958</link> <dc:creator>tdc</dc:creator> <pubDate>Thu, 24 Nov 2011 11:48:11 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=260#comment-62958</guid> <description>I know this is old, but I just noticed it gets even worse if you use the other way of calling cellfun (which I&#039;ve been using a lot):&lt;pre lang=&quot;matlab&quot;&gt;
&gt;&gt; c = mat2cell(1:1e6,1,repmat(1,1,1e6));
&gt;&gt; tic, d=cellfun(&#039;isempty&#039;,c); toc
Elapsed time is 0.034638 seconds.&gt;&gt; tic, d=cellfun(@isempty,c); toc
Elapsed time is 0.859156 seconds.&gt;&gt; tic, d=cellfun(@(x) isempty(x),c); toc
Elapsed time is 7.961039 seconds.
&lt;/pre&gt;</description> <content:encoded><![CDATA[<p>I know this is old, but I just noticed it gets even worse if you use the other way of calling cellfun (which I&#8217;ve been using a lot):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; c = mat2cell<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #F0F;">:</span>1e6,<span style="color: #33f;">1</span>,<span style="color: #0000FF;">repmat</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,1e6<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
&gt;&gt; <span style="color: #0000FF;">tic</span>, d=<span style="color: #0000FF;">cellfun</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'isempty'</span>,c<span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">toc</span>
Elapsed time <span style="color: #0000FF;">is</span> <span style="color: #33f;">0.034638</span> seconds.
&nbsp;
&gt;&gt; <span style="color: #0000FF;">tic</span>, d=<span style="color: #0000FF;">cellfun</span><span style="color: #080;">&#40;</span>@<span style="color: #0000FF;">isempty</span>,c<span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">toc</span>
Elapsed time <span style="color: #0000FF;">is</span> <span style="color: #33f;">0.859156</span> seconds.
&nbsp;
&gt;&gt; <span style="color: #0000FF;">tic</span>, d=<span style="color: #0000FF;">cellfun</span><span style="color: #080;">&#40;</span>@<span style="color: #080;">&#40;</span>x<span style="color: #080;">&#41;</span> <span style="color: #0000FF;">isempty</span><span style="color: #080;">&#40;</span>x<span style="color: #080;">&#41;</span>,c<span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">toc</span>
Elapsed time <span style="color: #0000FF;">is</span> <span style="color: #33f;">7.961039</span> seconds.</pre></div></div>]]></content:encoded> </item> <item><title>By: datestr performance &#124; Undocumented Matlab</title><link>http://undocumentedmatlab.com/blog/cellfun-undocumented-performance-boost/#comment-58733</link> <dc:creator>datestr performance &#124; Undocumented Matlab</dc:creator> <pubDate>Wed, 05 Oct 2011 20:17:50 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=260#comment-58733</guid> <description>[...] Different performance hotspots can have different solutions: caching, vectorization, internal library functions, undocumented graphics properties, smart property selection, smart function selection, smart indexing, smart parameter selection etc. [...]</description> <content:encoded><![CDATA[<p>[...] Different performance hotspots can have different solutions: caching, vectorization, internal library functions, undocumented graphics properties, smart property selection, smart function selection, smart indexing, smart parameter selection etc. [...]</p> ]]></content:encoded> </item> <item><title>By: Ashish Sadanadnan</title><link>http://undocumentedmatlab.com/blog/cellfun-undocumented-performance-boost/#comment-591</link> <dc:creator>Ashish Sadanadnan</dc:creator> <pubDate>Wed, 13 May 2009 03:54:16 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=260#comment-591</guid> <description>Yair,
I wasn&#039;t disputing your results. Just wanted to show that the factor has improved significantly in newer version (65 to 17). Of course, 17 times faster is still very significant as you pointed out.- Ashish.</description> <content:encoded><![CDATA[<p>Yair,<br
/> I wasn&#8217;t disputing your results. Just wanted to show that the factor has improved significantly in newer version (65 to 17). Of course, 17 times faster is still very significant as you pointed out.</p><p>- Ashish.</p> ]]></content:encoded> </item> <item><title>By: Loren S</title><link>http://undocumentedmatlab.com/blog/cellfun-undocumented-performance-boost/#comment-567</link> <dc:creator>Loren S</dc:creator> <pubDate>Tue, 12 May 2009 11:10:39 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=260#comment-567</guid> <description>Yair-As I noted to you on my blog, MATLAB doesn&#039;t convert from FH to string method because the user might have overridden whatever the method, e.g., isempty.  MATLAB could, at runtime, see if it&#039;s overridden, and if not, call the optimized version.  But it can&#039;t do that blindly without risk of wrong answers.--Loren</description> <content:encoded><![CDATA[<p>Yair-</p><p>As I noted to you on my blog, MATLAB doesn&#8217;t convert from FH to string method because the user might have overridden whatever the method, e.g., isempty.  MATLAB could, at runtime, see if it&#8217;s overridden, and if not, call the optimized version.  But it can&#8217;t do that blindly without risk of wrong answers.</p><p>&#8211;Loren</p> ]]></content:encoded> </item> <item><title>By: Naor</title><link>http://undocumentedmatlab.com/blog/cellfun-undocumented-performance-boost/#comment-554</link> <dc:creator>Naor</dc:creator> <pubDate>Tue, 12 May 2009 01:12:26 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=260#comment-554</guid> <description>wow. that&#039;s a pretty significant unnecessary slowdown. at least this would be easy to catch with the profiler.</description> <content:encoded><![CDATA[<p>wow. that&#8217;s a pretty significant unnecessary slowdown. at least this would be easy to catch with the profiler.</p> ]]></content:encoded> </item> <item><title>By: Yair Altman</title><link>http://undocumentedmatlab.com/blog/cellfun-undocumented-performance-boost/#comment-552</link> <dc:creator>Yair Altman</dc:creator> <pubDate>Mon, 11 May 2009 23:32:27 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=260#comment-552</guid> <description>Ashish - actually your results show a factor of 17 between the slower @isempty and the faster &#039;isempty&#039;, consistent with the results I posted above (my reported factor of 65 is almost the same order of magnitude as 17, and may be due to external platform-dependent factors).The absolute values of the results of course depend on the platform: my results were for a run-down heavily-loaded laptop... The important thing here is the factor between @isempty and &#039;isempty&#039; - not the absolute values. And a factor of 17 is still high enough to be taken into consideration in a performance-critical application.</description> <content:encoded><![CDATA[<p>Ashish &#8211; actually your results show a factor of 17 between the slower @isempty and the faster &#8216;isempty&#8217;, consistent with the results I posted above (my reported factor of 65 is almost the same order of magnitude as 17, and may be due to external platform-dependent factors).</p><p>The absolute values of the results of course depend on the platform: my results were for a run-down heavily-loaded laptop&#8230; The important thing here is the factor between @isempty and &#8216;isempty&#8217; &#8211; not the absolute values. And a factor of 17 is still high enough to be taken into consideration in a performance-critical application.</p> ]]></content:encoded> </item> <item><title>By: Ashish Sadanadnan</title><link>http://undocumentedmatlab.com/blog/cellfun-undocumented-performance-boost/#comment-551</link> <dc:creator>Ashish Sadanadnan</dc:creator> <pubDate>Mon, 11 May 2009 23:26:33 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=260#comment-551</guid> <description>They seem to already have improved it quite a bit in R2009a; here are my results from running your code:&gt;&gt; c = mat2cell(1:1e6,1,repmat(1,1,1e6));
&gt;&gt; tic, d=cellfun(&#039;isempty&#039;,c); toc
Elapsed time is 0.032880 seconds.
&gt;&gt; tic, d=cellfun(@isempty,c); toc
Elapsed time is 0.563284 seconds.</description> <content:encoded><![CDATA[<p>They seem to already have improved it quite a bit in R2009a; here are my results from running your code:</p><p>&gt;&gt; c = mat2cell(1:1e6,1,repmat(1,1,1e6));<br
/> &gt;&gt; tic, d=cellfun(&#8216;isempty&#8217;,c); toc<br
/> Elapsed time is 0.032880 seconds.<br
/> &gt;&gt; tic, d=cellfun(@isempty,c); toc<br
/> Elapsed time is 0.563284 seconds.</p> ]]></content:encoded> </item> </channel> </rss>

<!-- W3 Total Cache: Minify debug info:
Engine:             disk: basic
Theme:              b7666
Template:           single
-->
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: undocumentedmatlab.com @ 2012-02-09 06:03:16 -->

<!-- W3 Total Cache: Page cache debug info:
Engine:             disk: enhanced
Cache key:          blog/cellfun-undocumented-performance-boost/feed/_index.xml_gzip
Caching:            enabled
Status:             not cached
Creation Time:      0.610s
Header info:
X-Pingback:         http://undocumentedmatlab.com/blog/xmlrpc.php
Set-Cookie:         wpgb_visit_last_php-default=1328792596; expires=Fri, 08-Feb-2013 13:03:16 GMT; path=/
Link:               <http://undocumentedmatlab.com/?p=260>; rel=shortlink
Content-Type:       text/xml; charset=UTF-8
Last-Modified:      Thu, 09 Feb 2012 13:03:16 GMT
Vary:               Accept-Encoding, Cookie
Expires:            Thu, 09 Feb 2012 14:03:16 GMT
Pragma:             public
Cache-Control:      public, must-revalidate, proxy-revalidate
Etag:               1d58930ae40446629f4ac91ff5b443eb
Content-Encoding:   gzip
-->
