<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Benchmarking Perl Subroutine Calls</title>
	<atom:link href="http://curiousprogrammer.wordpress.com/2010/06/21/benchmarking-perl-subroutine-calls/feed/" rel="self" type="application/rss+xml" />
	<link>http://curiousprogrammer.wordpress.com/2010/06/21/benchmarking-perl-subroutine-calls/</link>
	<description>Leveraging Perl and Emacs</description>
	<lastBuildDate>Tue, 07 May 2013 11:25:25 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Perl Compiler Speed &#8211; It&#8217;s Fast! &#171; A Curious Programmer</title>
		<link>http://curiousprogrammer.wordpress.com/2010/06/21/benchmarking-perl-subroutine-calls/#comment-8330</link>
		<dc:creator><![CDATA[Perl Compiler Speed &#8211; It&#8217;s Fast! &#171; A Curious Programmer]]></dc:creator>
		<pubDate>Tue, 31 Aug 2010 07:12:35 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=1067#comment-8330</guid>
		<description><![CDATA[[...] Benchmarking Perl Subroutine Calls [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Benchmarking Perl Subroutine Calls [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jared</title>
		<link>http://curiousprogrammer.wordpress.com/2010/06/21/benchmarking-perl-subroutine-calls/#comment-8143</link>
		<dc:creator><![CDATA[Jared]]></dc:creator>
		<pubDate>Thu, 01 Jul 2010 21:58:44 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=1067#comment-8143</guid>
		<description><![CDATA[@Kevan

&lt;blockquote&gt;While generally not considered best practice, I think few people would complain about accessing them directly as $_[0] and $_[1] if the function itself is only a few lines.&lt;/blockquote&gt;

Interesting - there seems to be a split on this.  I don&#039;t like to see direct access of @_ elements in any code.  Although admittedly I occasionally do it in one-liners I always feel dirty afterwards.  I think Juster agrees and zloyrusskiy disagrees.

I also like the array unpacking idiom (my %args = @_).  I flit between using it and not using it.  Normally, speed of unpacking doesn&#039;t matter *that* much to me apart from the type of shims I discussed in the &lt;a href=&quot;http://curiousprogrammer.wordpress.com/2010/06/28/abstraction-and-subroutines/&quot; rel=&quot;nofollow&quot;&gt;Abstraction and Subroutines post&lt;/a&gt;.

You&#039;ve piqued my interest in Perl 6 with your mention of the flexible handling of subroutine arguments.  Although I&#039;m also a little bit sad that Perl 5 doesn&#039;t have anything as good as lisp macros.  Even as weak a variant as emacs lisp has such goodies as &lt;a href=&quot;http://curiousprogrammer.wordpress.com/2009/08/16/elisp-keyword-params/&quot; rel=&quot;nofollow&quot;&gt;keyword parameters&lt;/a&gt; easily bolted on by macros in a library.

@draegtun - good point :)]]></description>
		<content:encoded><![CDATA[<p>@Kevan</p>
<blockquote><p>While generally not considered best practice, I think few people would complain about accessing them directly as $_[0] and $_[1] if the function itself is only a few lines.</p></blockquote>
<p>Interesting &#8211; there seems to be a split on this.  I don&#8217;t like to see direct access of @_ elements in any code.  Although admittedly I occasionally do it in one-liners I always feel dirty afterwards.  I think Juster agrees and zloyrusskiy disagrees.</p>
<p>I also like the array unpacking idiom (my %args = @_).  I flit between using it and not using it.  Normally, speed of unpacking doesn&#8217;t matter *that* much to me apart from the type of shims I discussed in the <a href="http://curiousprogrammer.wordpress.com/2010/06/28/abstraction-and-subroutines/" rel="nofollow">Abstraction and Subroutines post</a>.</p>
<p>You&#8217;ve piqued my interest in Perl 6 with your mention of the flexible handling of subroutine arguments.  Although I&#8217;m also a little bit sad that Perl 5 doesn&#8217;t have anything as good as lisp macros.  Even as weak a variant as emacs lisp has such goodies as <a href="http://curiousprogrammer.wordpress.com/2009/08/16/elisp-keyword-params/" rel="nofollow">keyword parameters</a> easily bolted on by macros in a library.</p>
<p>@draegtun &#8211; good point <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: draegtun</title>
		<link>http://curiousprogrammer.wordpress.com/2010/06/21/benchmarking-perl-subroutine-calls/#comment-8115</link>
		<dc:creator><![CDATA[draegtun]]></dc:creator>
		<pubDate>Wed, 23 Jun 2010 09:43:37 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=1067#comment-8115</guid>
		<description><![CDATA[Hi Jared,

Yes I understand what you&#039;re trying to show but its nice to see that the idiomatic empty loop is actually faster in Perl :)

/I3az/]]></description>
		<content:encoded><![CDATA[<p>Hi Jared,</p>
<p>Yes I understand what you&#8217;re trying to show but its nice to see that the idiomatic empty loop is actually faster in Perl <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>/I3az/</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevan Benson</title>
		<link>http://curiousprogrammer.wordpress.com/2010/06/21/benchmarking-perl-subroutine-calls/#comment-8114</link>
		<dc:creator><![CDATA[Kevan Benson]]></dc:creator>
		<pubDate>Tue, 22 Jun 2010 22:38:33 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=1067#comment-8114</guid>
		<description><![CDATA[@Jared - Understood.  My point wasn&#039;t to show Perl was faster in a specific portion of your tests, but to show that quick benchmarks often yield less than pristine results.

For example, you make the assumption that you need to assign variables for the passed values in f2.  While generally not considered best practice, I think few people would complain about accessing them directly as $_[0] and $_[1]  if the function itself is only a few lines (I know I can make arguments both ways for a function that small).  That brings the results much closer to what you are seeing in Python, but still slower.

The directions the languages have gone are very different, and it might be more fruitful to benchmark common usages in each (although that&#039;s a much larger task).  Perl&#039;s arguments as a list with light prototyping sugar yields some interesting and useful practices, but so do python&#039;s stricter prototypes and polymorphism.  If each is commonly used in a manner that requires extra processing, that skews the result.  Your testing of a function that unpacks some variables shows you at least thought about the base case of this.  For example, I&#039;m a fan of using hash semantics to define the list of variables passed in as a list of named parameters, but that&#039;s less than ideal for speed.  E.g. 
sub myfunc {
  my %ops = @_;
}
myfunc(param1 =&gt; &#039;value1&#039;, param2 =&gt; &#039;value2&#039;);

An interesting tangent to this is how much boilerplate the language lets you remove from this.  Chromatic touched on this when referring to a YAPC talk in his blog at http://www.modernperlbooks.com/mt/2010/06/when-assembly-leaks-through.html.  Perl 6 gives you everything I&#039;ve mentioned from both languages plus much more; real named arguments, positional arguments, or slurpy arguments, and you can mix them in a single prototype.  Add multiple dispatch and... wow.  Yes, this is blatant fanboi advertising.  I can&#039;t help it. ;)

Okay, my windbag has sufficiently deflated.]]></description>
		<content:encoded><![CDATA[<p>@Jared &#8211; Understood.  My point wasn&#8217;t to show Perl was faster in a specific portion of your tests, but to show that quick benchmarks often yield less than pristine results.</p>
<p>For example, you make the assumption that you need to assign variables for the passed values in f2.  While generally not considered best practice, I think few people would complain about accessing them directly as $_[0] and $_[1]  if the function itself is only a few lines (I know I can make arguments both ways for a function that small).  That brings the results much closer to what you are seeing in Python, but still slower.</p>
<p>The directions the languages have gone are very different, and it might be more fruitful to benchmark common usages in each (although that&#8217;s a much larger task).  Perl&#8217;s arguments as a list with light prototyping sugar yields some interesting and useful practices, but so do python&#8217;s stricter prototypes and polymorphism.  If each is commonly used in a manner that requires extra processing, that skews the result.  Your testing of a function that unpacks some variables shows you at least thought about the base case of this.  For example, I&#8217;m a fan of using hash semantics to define the list of variables passed in as a list of named parameters, but that&#8217;s less than ideal for speed.  E.g.<br />
sub myfunc {<br />
  my %ops = @_;<br />
}<br />
myfunc(param1 =&gt; &#8216;value1&#8242;, param2 =&gt; &#8216;value2&#8242;);</p>
<p>An interesting tangent to this is how much boilerplate the language lets you remove from this.  Chromatic touched on this when referring to a YAPC talk in his blog at <a href="http://www.modernperlbooks.com/mt/2010/06/when-assembly-leaks-through.html" rel="nofollow">http://www.modernperlbooks.com/mt/2010/06/when-assembly-leaks-through.html</a>.  Perl 6 gives you everything I&#8217;ve mentioned from both languages plus much more; real named arguments, positional arguments, or slurpy arguments, and you can mix them in a single prototype.  Add multiple dispatch and&#8230; wow.  Yes, this is blatant fanboi advertising.  I can&#8217;t help it. <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Okay, my windbag has sufficiently deflated.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jared</title>
		<link>http://curiousprogrammer.wordpress.com/2010/06/21/benchmarking-perl-subroutine-calls/#comment-8113</link>
		<dc:creator><![CDATA[Jared]]></dc:creator>
		<pubDate>Tue, 22 Jun 2010 20:34:36 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=1067#comment-8113</guid>
		<description><![CDATA[@Adam - Good (and surprising, to me) to know.  I didn&#039;t know Perl supported this sort of optimisation.

@draegtun &amp; Kevan - Okay, it is kinda nice to know how to improve the loop slightly.  I remember the days that 1 .. 10_000_000 would construct an array in memory :)

But that isn&#039;t what I&#039;m interested in here.  I&#039;m interested in how fast subroutine calls are.  That is the reason I measured the loop speed first so I can take it out of the equation.  And in my tests, it looks like Python calls are significantly faster than Perl calls (although not sufficiently faster for me to care/switch).]]></description>
		<content:encoded><![CDATA[<p>@Adam &#8211; Good (and surprising, to me) to know.  I didn&#8217;t know Perl supported this sort of optimisation.</p>
<p>@draegtun &amp; Kevan &#8211; Okay, it is kinda nice to know how to improve the loop slightly.  I remember the days that 1 .. 10_000_000 would construct an array in memory <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>But that isn&#8217;t what I&#8217;m interested in here.  I&#8217;m interested in how fast subroutine calls are.  That is the reason I measured the loop speed first so I can take it out of the equation.  And in my tests, it looks like Python calls are significantly faster than Perl calls (although not sufficiently faster for me to care/switch).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevan Benson</title>
		<link>http://curiousprogrammer.wordpress.com/2010/06/21/benchmarking-perl-subroutine-calls/#comment-8112</link>
		<dc:creator><![CDATA[Kevan Benson]]></dc:creator>
		<pubDate>Tue, 22 Jun 2010 19:44:53 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=1067#comment-8112</guid>
		<description><![CDATA[As with all benchmarks, domain knowledge is very important.

for ($i = 0; $i &lt; 10_000_000; ++$i) {
       1;
}
# time perl tmp.pl

real    0m0.708s
user    0m0.704s
sys     0m0.004s

for my $i (1 .. 10_000_000) {
       1;
}
# time perl tmp.pl

real    0m0.523s
user    0m0.520s
sys     0m0.002s

for (1 .. 10_000_000) {
        1;
}
# time perl tmp.pl

real    0m0.493s
user    0m0.490s
sys     0m0.002s

Note the last one.  The iterator variable is still available through the topic, $_.  There&#039;s no reason to assign it to a separate variable every iteration, and if you need it, that&#039;s what the topic is for.

Just because Perl allows you to write in any style you want, doesn&#039;t mean the code will be optimal for execution.]]></description>
		<content:encoded><![CDATA[<p>As with all benchmarks, domain knowledge is very important.</p>
<p>for ($i = 0; $i &lt; 10_000_000; ++$i) {<br />
       1;<br />
}<br />
# time perl tmp.pl</p>
<p>real    0m0.708s<br />
user    0m0.704s<br />
sys     0m0.004s</p>
<p>for my $i (1 .. 10_000_000) {<br />
       1;<br />
}<br />
# time perl tmp.pl</p>
<p>real    0m0.523s<br />
user    0m0.520s<br />
sys     0m0.002s</p>
<p>for (1 .. 10_000_000) {<br />
        1;<br />
}<br />
# time perl tmp.pl</p>
<p>real    0m0.493s<br />
user    0m0.490s<br />
sys     0m0.002s</p>
<p>Note the last one.  The iterator variable is still available through the topic, $_.  There&#039;s no reason to assign it to a separate variable every iteration, and if you need it, that&#039;s what the topic is for.</p>
<p>Just because Perl allows you to write in any style you want, doesn&#039;t mean the code will be optimal for execution.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: draegtun</title>
		<link>http://curiousprogrammer.wordpress.com/2010/06/21/benchmarking-perl-subroutine-calls/#comment-8110</link>
		<dc:creator><![CDATA[draegtun]]></dc:creator>
		<pubDate>Tue, 22 Jun 2010 11:54:40 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=1067#comment-8110</guid>
		<description><![CDATA[For comparable loop to Python example then its more idiomatic and (pretty sure) faster to use:

  for my $i (1 .. 10_000_000 ) { ... }

BTW, benchmarks like this have come up on Stackoverflow from time to time.  For eg.  http://stackoverflow.com/questions/1984871/why-is-my-python-version-slower-than-my-perl-version-closed

/I3az/]]></description>
		<content:encoded><![CDATA[<p>For comparable loop to Python example then its more idiomatic and (pretty sure) faster to use:</p>
<p>  for my $i (1 .. 10_000_000 ) { &#8230; }</p>
<p>BTW, benchmarks like this have come up on Stackoverflow from time to time.  For eg.  <a href="http://stackoverflow.com/questions/1984871/why-is-my-python-version-slower-than-my-perl-version-closed" rel="nofollow">http://stackoverflow.com/questions/1984871/why-is-my-python-version-slower-than-my-perl-version-closed</a></p>
<p>/I3az/</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam Kennedy</title>
		<link>http://curiousprogrammer.wordpress.com/2010/06/21/benchmarking-perl-subroutine-calls/#comment-8109</link>
		<dc:creator><![CDATA[Adam Kennedy]]></dc:creator>
		<pubDate>Tue, 22 Jun 2010 11:32:04 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=1067#comment-8109</guid>
		<description><![CDATA[For f1, in Perl if a function takes no parameters I believe you can speed it up by telling it as much via prototypes.

sub f1 () {

}]]></description>
		<content:encoded><![CDATA[<p>For f1, in Perl if a function takes no parameters I believe you can speed it up by telling it as much via prototypes.</p>
<p>sub f1 () {</p>
<p>}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jared</title>
		<link>http://curiousprogrammer.wordpress.com/2010/06/21/benchmarking-perl-subroutine-calls/#comment-8108</link>
		<dc:creator><![CDATA[Jared]]></dc:creator>
		<pubDate>Tue, 22 Jun 2010 08:01:35 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=1067#comment-8108</guid>
		<description><![CDATA[@Nilson - I tried strings which just made it slower.  Python was able to handle them better.  Maybe it is the reassigning of the parameter list from @_ that is slowing Perl down.

@Bartek - Method calls are significantly slower than subroutine calls, in Perl at least.

@James - I&#039;m using version 5.10.1 which should have fixed that regression.  However, the subroutine using shift is still slightly quicker.

I&#039;ll post more benchmarks shortly.]]></description>
		<content:encoded><![CDATA[<p>@Nilson &#8211; I tried strings which just made it slower.  Python was able to handle them better.  Maybe it is the reassigning of the parameter list from @_ that is slowing Perl down.</p>
<p>@Bartek &#8211; Method calls are significantly slower than subroutine calls, in Perl at least.</p>
<p>@James &#8211; I&#8217;m using version 5.10.1 which should have fixed that regression.  However, the subroutine using shift is still slightly quicker.</p>
<p>I&#8217;ll post more benchmarks shortly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://curiousprogrammer.wordpress.com/2010/06/21/benchmarking-perl-subroutine-calls/#comment-8106</link>
		<dc:creator><![CDATA[James]]></dc:creator>
		<pubDate>Mon, 21 Jun 2010 17:35:31 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=1067#comment-8106</guid>
		<description><![CDATA[What version of perl are you running this under?
I believe that list assignment is usually slower than shifting each item off of @_, and there was a regression in 5.10.0 that slowed it down much more. I would be interested in seeing how this version of f2 stacks up:

sub f2
{
    my $x = shift;
    my $y = shift;
    return ($x, $y);
}]]></description>
		<content:encoded><![CDATA[<p>What version of perl are you running this under?<br />
I believe that list assignment is usually slower than shifting each item off of @_, and there was a regression in 5.10.0 that slowed it down much more. I would be interested in seeing how this version of f2 stacks up:</p>
<p>sub f2<br />
{<br />
    my $x = shift;<br />
    my $y = shift;<br />
    return ($x, $y);<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>
