Seems to be the case that named hash lookups are (marginally, but consistently) quicker: {
my $ref = { 1 .. 1e6 };
my %h = 1 .. 1e6;
cmpthese -5,{
a => sub{ exists $ref->{$_} and 1 for 1 .. 1e6; },
b => sub{ exists $h{$_} and 1 for 1 .. 1e6; }
}
};;
Rate a b
a 1.24/s -- -3%
b 1.28/s 3% --
Rate a b
a 1.36/s -- -5%
b 1.43/s 5% --
Rate a b
a 1.24/s -- -3%
b 1.28/s 3% --
Rate a b
a 1.23/s -- -5%
b 1.29/s 5% --
Rate a b
a 1.27/s -- -3%
b 1.30/s 3% --
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|