Skip to content

Instantly share code, notes, and snippets.

@marcusramberg
Created August 29, 2012 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcusramberg/3515534 to your computer and use it in GitHub Desktop.
Save marcusramberg/3515534 to your computer and use it in GitHub Desktop.
~/Source/web_irc(branch:master*) » perl t.pl marcus@mrbook
Rate hack sprintf normal
hack 1488095/s -- -64% -80%
sprintf 4149378/s 179% -- -44%
normal 7407407/s 398% 79% --
------------------------------------------------------------
~/Source/web_irc(branch:master*) » cat t.pl marcus@mrbook
#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
use Benchmark 'cmpthese';
cmpthese(10000000, {
normal => sub {
my $res = 5 * 5;
"Result is: $res";
},
hack => sub {
my $res = 5 * 5;
"Result is: @{[$res]}"
},
sprintf => sub {
my $res = 5 * 5;
sprintf "Result is: %s",$res
}
})
@proller
Copy link

proller commented Aug 29, 2012

hack => sub {
"Result is: @{[5 * 5]}"
},
join => sub {
join '', "Result is: ", 5 * 5;
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment