if ($param eq 'this' || $param eq 'that'
|| $param eq 'the other') {
...
}
####
if ($param eq any('this', 'that', 'the other') {
...
}
####
$result = any(1,2,3) * 2;
if ($result == 4) {...}
####
$ /usr/bin/perl ./benchmark.pl
all: numeric (few)
Rate Quantum-Superpositions Junction
Quantum-Superpositions 1842/s -- -94%
Junction 30303/s 1545% --
all: numeric (lots)
Rate Quantum-Superpositions Junction
Quantum-Superpositions 1364/s -- -44%
Junction 2433/s 78% --
all: string
Rate Quantum-Superpositions Junction
Quantum-Superpositions 1689/s -- -79%
Junction 8000/s 374% --
any: numeric (few)
Rate Quantum-Superpositions Junction
Quantum-Superpositions 747/s -- -97%
Junction 28571/s 3725% --
any: numeric (lots)
Rate Quantum-Superpositions Junction
Quantum-Superpositions 37.9/s -- -97%
Junction 1429/s 3672% --
any: string
Rate Quantum-Superpositions Junction
Quantum-Superpositions 317/s -- -95%
Junction 6422/s 1928% --
####
#!/usr/bin/perl
use strict;
use warnings;
use Junction qw/ xall xany /;
use Quantum::Superpositions qw/ all any /;
use Benchmark ':all';
print "all: numeric (few)\n";
cmpthese(30_000,{
Junction => sub {
1 if xall(1..5) == 2;
},
'Quantum-Superpositions' => sub {
1 if all(1..5) == 2;
},
});
print "\nall: numeric (lots)\n";
cmpthese(30_000,{
Junction => sub {
1 if xall(1..300) == 250;
},
'Quantum-Superpositions' => sub {
1 if all(1..300) == 250;
},
});
print "\nall: string\n";
cmpthese(10_000,{
Junction => sub {
1 if xall('a'..'z') eq 'z';
},
'Quantum-Superpositions' => sub {
1 if all('a'..'z') eq 'z';
},
});
print "\nany: numeric (few)\n";
cmpthese(30_000,{
Junction => sub {
1 if xany(1..5) == 2;
},
'Quantum-Superpositions' => sub {
1 if any(1..5) == 2;
},
});
print "\nany: numeric (lots)\n";
cmpthese(2_000,{
Junction => sub {
1 if xany(1..300) == 250;
},
'Quantum-Superpositions' => sub {
1 if any(1..300) == 250;
},
});
print "\nany: string\n";
cmpthese(7_000,{
Junction => sub {
1 if xany('a'..'z') eq 'z';
},
'Quantum-Superpositions' => sub {
1 if any('a'..'z') eq 'z';
},
});