<?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="https://undocumentedmatlab.com/articles/cellfun-undocumented-performance-boost/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com/articles/cellfun-undocumented-performance-boost?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=cellfun-undocumented-performance-boost</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Mon, 29 May 2023 03:59:22 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>
	<item>
		<title>
		By: Sunham		</title>
		<link>https://undocumentedmatlab.com/articles/cellfun-undocumented-performance-boost#comment-521709</link>

		<dc:creator><![CDATA[Sunham]]></dc:creator>
		<pubDate>Mon, 29 May 2023 03:59:22 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=260#comment-521709</guid>

					<description><![CDATA[This is an old article, but the issue persists even in 2023.
2023a:

z = mat2cell(1:1e6,1,repmat(1,1,1e6));
f = @() cellfun(&#039;isempty&#039;,z);
g = @() cellfun(@isempty,z);

a1=timeit(f)
a1 =
    0.0053
a2=timeit(g)
a2 =
    0.7142

a2/a1
ans =
  135.1974]]></description>
			<content:encoded><![CDATA[<p>This is an old article, but the issue persists even in 2023.<br />
2023a:</p>
<p>z = mat2cell(1:1e6,1,repmat(1,1,1e6));<br />
f = @() cellfun(&#8216;isempty&#8217;,z);<br />
g = @() cellfun(@isempty,z);</p>
<p>a1=timeit(f)<br />
a1 =<br />
    0.0053<br />
a2=timeit(g)<br />
a2 =<br />
    0.7142</p>
<p>a2/a1<br />
ans =<br />
  135.1974</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: juanpi carbajal		</title>
		<link>https://undocumentedmatlab.com/articles/cellfun-undocumented-performance-boost#comment-420899</link>

		<dc:creator><![CDATA[juanpi carbajal]]></dc:creator>
		<pubDate>Thu, 22 Mar 2018 13:22:41 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=260#comment-420899</guid>

					<description><![CDATA[Octave 4.2.2

&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.0282919 seconds.

&gt;&gt; tic, d=cellfun(@isempty,c); toc
Elapsed time is 0.0258329 seconds.

&gt;&gt; 0.0258329 / 0.0282919
ans =  0.91308
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>Octave 4.2.2</p>
<pre lang="matlab">
>> c = mat2cell(1:1e6,1,repmat(1,1,1e6));
>> tic, d=cellfun('isempty',c); toc
Elapsed time is 0.0282919 seconds.

>> tic, d=cellfun(@isempty,c); toc
Elapsed time is 0.0258329 seconds.

>> 0.0258329 / 0.0282919
ans =  0.91308
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Anon		</title>
		<link>https://undocumentedmatlab.com/articles/cellfun-undocumented-performance-boost#comment-417448</link>

		<dc:creator><![CDATA[Anon]]></dc:creator>
		<pubDate>Mon, 11 Dec 2017 16:07:49 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=260#comment-417448</guid>

					<description><![CDATA[2017b

&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.011489 seconds.

&gt;&gt; tic, d=cellfun(@isempty,c); toc
Elapsed time is 0.927122 seconds.

&gt;&gt; 0.927122/0.011489
ans =
   80.6965
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>2017b</p>
<pre lang="matlab">
>> c = mat2cell(1:1e6,1,repmat(1,1,1e6));
>> tic, d=cellfun('isempty',c); toc
Elapsed time is 0.011489 seconds.

>> tic, d=cellfun(@isempty,c); toc
Elapsed time is 0.927122 seconds.

>> 0.927122/0.011489
ans =
   80.6965
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Carlo Monjaraz		</title>
		<link>https://undocumentedmatlab.com/articles/cellfun-undocumented-performance-boost#comment-396027</link>

		<dc:creator><![CDATA[Carlo Monjaraz]]></dc:creator>
		<pubDate>Tue, 13 Dec 2016 10:54:14 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=260#comment-396027</guid>

					<description><![CDATA[R2016a :/

&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.008351 seconds.

&gt;&gt; tic, d=cellfun(@isempty,c); toc
Elapsed time is 0.461371 seconds.

&gt;&gt; 0.461371 / 0.008351
ans =
   55.2474
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>R2016a :/</p>
<pre lang="matlab">
>> c = mat2cell(1:1e6,1,repmat(1,1,1e6));
>> tic, d=cellfun('isempty',c); toc
Elapsed time is 0.008351 seconds.

>> tic, d=cellfun(@isempty,c); toc
Elapsed time is 0.461371 seconds.

>> 0.461371 / 0.008351
ans =
   55.2474
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Marco Riani		</title>
		<link>https://undocumentedmatlab.com/articles/cellfun-undocumented-performance-boost#comment-359317</link>

		<dc:creator><![CDATA[Marco Riani]]></dc:creator>
		<pubDate>Mon, 19 Oct 2015 10:22:27 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=260#comment-359317</guid>

					<description><![CDATA[This is what happens in R2015b:

&lt;pre lang=&#039;matlab&#039;&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.011079 seconds.

&gt;&gt; tic, d=cellfun(@isempty,c); toc
Elapsed time is 0.618598 seconds.
&lt;/pre&gt;

The gap is still present]]></description>
			<content:encoded><![CDATA[<p>This is what happens in R2015b:</p>
<pre lang='matlab'>
>> c = mat2cell(1:1e6,1,repmat(1,1,1e6));
>> tic, d=cellfun('isempty',c); toc
Elapsed time is 0.011079 seconds.

>> tic, d=cellfun(@isempty,c); toc
Elapsed time is 0.618598 seconds.
</pre>
<p>The gap is still present</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Rody Oldenhuis		</title>
		<link>https://undocumentedmatlab.com/articles/cellfun-undocumented-performance-boost#comment-327223</link>

		<dc:creator><![CDATA[Rody Oldenhuis]]></dc:creator>
		<pubDate>Tue, 01 Jul 2014 08:32:53 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=260#comment-327223</guid>

					<description><![CDATA[MATLAB R2013a result: 

&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.038423 seconds.

&gt;&gt; tic, d=cellfun(@isempty,c); toc
Elapsed time is 0.681082 seconds.

&gt;&gt; 0.681082/0.038423
ans =
   17.7259
&lt;/pre&gt;

The MathWorks don&#039;t seem to be in a rush to optimize this...]]></description>
			<content:encoded><![CDATA[<p>MATLAB R2013a result: </p>
<pre lang="matlab"> 
>> c = mat2cell(1:1e6,1,repmat(1,1,1e6));
>> tic, d=cellfun('isempty',c); toc
Elapsed time is 0.038423 seconds.

>> tic, d=cellfun(@isempty,c); toc
Elapsed time is 0.681082 seconds.

>> 0.681082/0.038423
ans =
   17.7259
</pre>
<p>The MathWorks don&#8217;t seem to be in a rush to optimize this&#8230;</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: How to compute effectively string length of cell array of strings &#124; PHP Developer Resource		</title>
		<link>https://undocumentedmatlab.com/articles/cellfun-undocumented-performance-boost#comment-87977</link>

		<dc:creator><![CDATA[How to compute effectively string length of cell array of strings &#124; PHP Developer Resource]]></dc:creator>
		<pubDate>Tue, 29 May 2012 04:47:36 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=260#comment-87977</guid>

					<description><![CDATA[[...] &#8211; I found out the reason for the speedup. It is indeed recognition of length specifically. Thanks to @reve_etrange for the [...]]]></description>
			<content:encoded><![CDATA[<p>[&#8230;] &#8211; I found out the reason for the speedup. It is indeed recognition of length specifically. Thanks to @reve_etrange for the [&#8230;]</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: damayi		</title>
		<link>https://undocumentedmatlab.com/articles/cellfun-undocumented-performance-boost#comment-87250</link>

		<dc:creator><![CDATA[damayi]]></dc:creator>
		<pubDate>Wed, 23 May 2012 02:48:18 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=260#comment-87250</guid>

					<description><![CDATA[MATLAB 2011b result:
&lt;pre lang=&#039;matlab&#039;&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.032773 seconds.

&gt;&gt; tic, d=cellfun(@isempty,c); toc
Elapsed time is 2.100385 seconds.

&gt;&gt; 2.100385/0.032773
ans =
   64.0889
&lt;/pre&gt;
]]></description>
			<content:encoded><![CDATA[<p>MATLAB 2011b result:</p>
<pre lang='matlab'>
>> c = mat2cell(1:1e6,1,repmat(1,1,1e6));
>> tic, d=cellfun('isempty',c); toc
Elapsed time is 0.032773 seconds.

>> tic, d=cellfun(@isempty,c); toc
Elapsed time is 2.100385 seconds.

>> 2.100385/0.032773
ans =
   64.0889
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jordi Gutiérrez Hermoso		</title>
		<link>https://undocumentedmatlab.com/articles/cellfun-undocumented-performance-boost#comment-63587</link>

		<dc:creator><![CDATA[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><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/cellfun-undocumented-performance-boost#comment-62958&quot;&gt;tdc&lt;/a&gt;.

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/cf8cd43cdeb3

On 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>In reply to <a href="https://undocumentedmatlab.com/articles/cellfun-undocumented-performance-boost#comment-62958">tdc</a>.</p>
<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 ugc">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>
<pre lang="matlab">
octave:1> c = mat2cell(1:1e6,1,repmat(1,1,1e6));
octave:2> tic, d=cellfun('isempty',c); toc
Elapsed time is 0.0171831 seconds.
octave:3> tic, d=cellfun('isempty',c); toc
Elapsed time is 0.0182698 seconds.
octave:4> tic, d=cellfun('isempty',c); toc
Elapsed time is 0.0223808 seconds.

octave:5> tic, d=cellfun(@isempty,c); toc
Elapsed time is 0.0193319 seconds.
octave:6> tic, d=cellfun(@isempty,c); toc
Elapsed time is 0.01612 seconds.
octave:7> tic, d=cellfun(@isempty,c); toc
Elapsed time is 0.019449 seconds.
</pre>
<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>
<pre lang="matlab">
octave:8> tic, d=cellfun(@(x) isempty(x),c); toc
Elapsed time is 0.924903 seconds.
octave:9> tic, d=cellfun(@(x) isempty(x),c); toc
Elapsed time is 0.873197 seconds.
octave:10> tic, d=cellfun(@(x) isempty(x),c); toc
Elapsed time is 0.875425 seconds.
</pre>
<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>https://undocumentedmatlab.com/articles/cellfun-undocumented-performance-boost#comment-63578</link>

		<dc:creator><![CDATA[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><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/cellfun-undocumented-performance-boost#comment-63576&quot;&gt;Jordi Gutiérrez Hermoso&lt;/a&gt;.

@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>In reply to <a href="https://undocumentedmatlab.com/articles/cellfun-undocumented-performance-boost#comment-63576">Jordi Gutiérrez Hermoso</a>.</p>
<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>
	</channel>
</rss>
