[tpm] Is there a three-way version of...
J. Bobby Lopez
jbl at jbldata.com
Mon Jun 1 22:12:22 PDT 2009
Yep, chaining is faster, which makes sense. But figured I'd try to compare
them anyway.
Here are two scripts that I used for comparison:
test1.pl--------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
sub loop
{
my ($a, $b, $c, $d) = "";
for my $i (0..300000)
{
$a = get(0);
$b = get(5);
$c = get(10);
$d = get(14);
$a = $b if $a eq "-";
$a = $c if $a eq "-";
$a = $d if $a eq "-";
$a = "empty" if $a eq "-";
#print "$i - a: $a, b: $b, c: $c, d: $d", "\n";
}
}
sub get
{
my $r = 4;
my ($m) = @_;
my $a = int(rand($r)) + $m;
return $a if $a > ($m + $r) - 2;
return "-";
}
--------------------------------------------------------------
test2.pl--------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
sub loop
{
my ($a, $b, $c, $d) = "";
for my $i (0..300000)
{
$a = get(0);
$b = get(5);
$c = get(10);
$d = get(14);
$a = $a || $b || $c || $d || 'empty';
# print "$i - a: $a, b: $b, c: $c, d: $d", "\n";
}
}
sub get
{
my $r = 4;
my ($m) = @_;
my $a = int(rand($r)) + $m;
return $a if $a > ($m + $r) - 2;
return 0;
}
loop();
--------------------------------------------------------------
Here are the results from the tests ran on the above scripts:
test1.pl
jbl at blopez-d620:~/tmp$ time ./test1.pl
real 0m2.129s
user 0m2.120s
sys 0m0.008s
jbl at blopez-d620:~/tmp$ time ./test1.pl
real 0m2.023s
user 0m2.016s
sys 0m0.004s
jbl at blopez-d620:~/tmp$ time ./test1.pl
real 0m1.983s
user 0m1.976s
sys 0m0.008s
test2.pl
jbl at blopez-d620:~/tmp$ time ./test2.pl
real 0m1.612s
user 0m1.604s
sys 0m0.008s
jbl at blopez-d620:~/tmp$ time ./test2.pl
real 0m1.579s
user 0m1.576s
sys 0m0.004s
jbl at blopez-d620:~/tmp$ time ./test2.pl
real 0m1.625s
user 0m1.612s
sys 0m0.012s
--
J. Bobby Lopez
Web: http://jbldata.com/
Twitter: http://www.twitter.com/jbobbylopez
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20090602/c0cdb7de/attachment.html>
More information about the toronto-pm
mailing list