Hello eyepopslikeamosquito,
From testing using Perl 5.18.2, join(':', @$p) runs faster than $p->[0] .':'. $p->[1]. Although, it runs only slightly faster on newer Perl releases.
sub str_look {
my $cells = shift;
for my $p (@points) {
# my $h = $p->[0] . ':' . $p->[1];
# exists $cells->{$p->[0] . ':' . $p->[1]} or die;
exists $cells->{ join(':', @$p) } or die;
}
exists $cells->{'notfound'} and die;
exists $cells->{'notfound2'} and die;
exists $cells->{'notfound3'} and die;
}
Results:
str_look concat 34843.21/s
str_look join 42643.92/s
Update: Added st2_look including mat_hash by kcott.
...
sub st2_look {
my $cells = shift;
for my $p (@points) {
exists $cells->{ join(':',@$p) } or die;
}
exists $cells->{'notfound'} and die;
exists $cells->{'notfound2'} and die;
exists $cells->{'notfound3'} and die;
}
my $str_ref = str_hash();
my $st2_ref = str_hash();
my $big_ref = big_hash();
my $pak_ref = pak_hash();
my $mat_ref = mat_hash();
timethese 200000, {
Str => sub { str_look($str_ref) },
St2 => sub { st2_look($st2_ref) },
Big => sub { big_look($big_ref) },
Pak => sub { pak_look($pak_ref) },
Mat => sub { mat_look($mat_ref) },
};
Benchmark from Perl 5.18.2 (default Perl) on Mac OS X 10.11.6.
Benchmark: timing 200000 iterations of Big, Mat, Pak, St2, Str...
Big: 7 wallclock secs ( 6.73 usr + 0.00 sys = 6.73 CPU) @ 29717.68/s
+(n=200000)
Mat: 6 wallclock secs ( 5.38 usr + 0.00 sys = 5.38 CPU) @ 37174.72/s
+(n=200000)
Pak: 6 wallclock secs ( 6.43 usr + 0.00 sys = 6.43 CPU) @ 31104.20/s
+(n=200000)
St2: 5 wallclock secs ( 4.66 usr + 0.00 sys = 4.66 CPU) @ 42918.45/s
+(n=200000)
Str: 6 wallclock secs ( 5.72 usr + 0.00 sys = 5.72 CPU) @ 34965.03/s
+(n=200000)
Benchmark: timing 200000 iterations of Big, Mat, Pak, St2, Str...
Big: 6 wallclock secs ( 6.76 usr + 0.00 sys = 6.76 CPU) @ 29585.80/s
+(n=200000)
Mat: 4 wallclock secs ( 5.30 usr + 0.00 sys = 5.30 CPU) @ 37735.85/s
+(n=200000)
Pak: 6 wallclock secs ( 6.43 usr + 0.00 sys = 6.43 CPU) @ 31104.20/s
+(n=200000)
St2: 5 wallclock secs ( 4.65 usr + 0.00 sys = 4.65 CPU) @ 43010.75/s
+(n=200000)
Str: 6 wallclock secs ( 5.74 usr + 0.00 sys = 5.74 CPU) @ 34843.21/s
+(n=200000)
Benchmark: timing 200000 iterations of Big, Mat, Pak, St2, Str...
Big: 7 wallclock secs ( 6.79 usr + 0.00 sys = 6.79 CPU) @ 29455.08/s
+(n=200000)
Mat: 5 wallclock secs ( 5.32 usr + 0.00 sys = 5.32 CPU) @ 37593.98/s
+(n=200000)
Pak: 6 wallclock secs ( 6.43 usr + 0.00 sys = 6.43 CPU) @ 31104.20/s
+(n=200000)
St2: 3 wallclock secs ( 4.71 usr + 0.00 sys = 4.71 CPU) @ 42462.85/s
+(n=200000)
Str: 6 wallclock secs ( 5.74 usr + 0.00 sys = 5.74 CPU) @ 34843.21/s
+(n=200000)
Benchmark from Perl 5.22.3 on Mac OS X.
config_args='-Dprefix=/opt/perl-5.22.3 -sder -Dusethreads -Accflags=-m
+sse4.2'
Benchmark: timing 200000 iterations of Big, Mat, Pak, St2, Str...
Big: 7 wallclock secs ( 6.07 usr + 0.00 sys = 6.07 CPU) @ 32948.93/s
+(n=200000)
Mat: 4 wallclock secs ( 4.64 usr + 0.00 sys = 4.64 CPU) @ 43103.45/s
+(n=200000)
Pak: 6 wallclock secs ( 5.26 usr + 0.00 sys = 5.26 CPU) @ 38022.81/s
+(n=200000)
St2: 4 wallclock secs ( 4.60 usr + 0.00 sys = 4.60 CPU) @ 43478.26/s
+(n=200000)
Str: 5 wallclock secs ( 4.77 usr + 0.00 sys = 4.77 CPU) @ 41928.72/s
+(n=200000)
Benchmark: timing 200000 iterations of Big, Mat, Pak, St2, Str...
Big: 6 wallclock secs ( 6.01 usr + 0.00 sys = 6.01 CPU) @ 33277.87/s
+(n=200000)
Mat: 5 wallclock secs ( 4.77 usr + 0.00 sys = 4.77 CPU) @ 41928.72/s
+(n=200000)
Pak: 5 wallclock secs ( 5.32 usr + 0.00 sys = 5.32 CPU) @ 37593.98/s
+(n=200000)
St2: 5 wallclock secs ( 4.67 usr + 0.00 sys = 4.67 CPU) @ 42826.55/s
+(n=200000)
Str: 5 wallclock secs ( 4.87 usr + 0.00 sys = 4.87 CPU) @ 41067.76/s
+(n=200000)
Benchmark: timing 200000 iterations of Big, Mat, Pak, St2, Str...
Big: 6 wallclock secs ( 5.96 usr + 0.00 sys = 5.96 CPU) @ 33557.05/s
+(n=200000)
Mat: 5 wallclock secs ( 4.65 usr + 0.00 sys = 4.65 CPU) @ 43010.75/s
+(n=200000)
Pak: 5 wallclock secs ( 5.28 usr + 0.00 sys = 5.28 CPU) @ 37878.79/s
+(n=200000)
St2: 4 wallclock secs ( 4.67 usr + 0.00 sys = 4.67 CPU) @ 42826.55/s
+(n=200000)
Str: 5 wallclock secs ( 4.88 usr + 0.00 sys = 4.88 CPU) @ 40983.61/s
+(n=200000)
Benchmark from Perl 5.24.1 on Mac OS X.
config_args='-Dprefix=/opt/perl-5.24.1 -sder -Dusethreads -Accflags=-m
+sse4.2'
Benchmark: timing 200000 iterations of Big, Mat, Pak, St2, Str...
Big: 6 wallclock secs ( 5.93 usr + 0.00 sys = 5.93 CPU) @ 33726.81/s
+(n=200000)
Mat: 5 wallclock secs ( 4.66 usr + 0.00 sys = 4.66 CPU) @ 42918.45/s
+(n=200000)
Pak: 5 wallclock secs ( 5.24 usr + 0.00 sys = 5.24 CPU) @ 38167.94/s
+(n=200000)
St2: 5 wallclock secs ( 4.53 usr + 0.00 sys = 4.53 CPU) @ 44150.11/s
+(n=200000)
Str: 4 wallclock secs ( 4.64 usr + 0.00 sys = 4.64 CPU) @ 43103.45/s
+(n=200000)
Benchmark: timing 200000 iterations of Big, Mat, Pak, St2, Str...
Big: 6 wallclock secs ( 5.94 usr + 0.00 sys = 5.94 CPU) @ 33670.03/s
+(n=200000)
Mat: 5 wallclock secs ( 4.76 usr + 0.00 sys = 4.76 CPU) @ 42016.81/s
+(n=200000)
Pak: 5 wallclock secs ( 5.26 usr + 0.00 sys = 5.26 CPU) @ 38022.81/s
+(n=200000)
St2: 5 wallclock secs ( 4.49 usr + 0.00 sys = 4.49 CPU) @ 44543.43/s
+(n=200000)
Str: 5 wallclock secs ( 4.67 usr + 0.00 sys = 4.67 CPU) @ 42826.55/s
+(n=200000)
Benchmark: timing 200000 iterations of Big, Mat, Pak, St2, Str...
Big: 6 wallclock secs ( 5.96 usr + 0.00 sys = 5.96 CPU) @ 33557.05/s
+(n=200000)
Mat: 5 wallclock secs ( 4.66 usr + 0.00 sys = 4.66 CPU) @ 42918.45/s
+(n=200000)
Pak: 5 wallclock secs ( 5.38 usr + 0.00 sys = 5.38 CPU) @ 37174.72/s
+(n=200000)
St2: 5 wallclock secs ( 4.50 usr + 0.00 sys = 4.50 CPU) @ 44444.44/s
+(n=200000)
Str: 4 wallclock secs ( 4.68 usr + 0.00 sys = 4.68 CPU) @ 42735.04/s
+(n=200000)
Regards, Mario
-
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.