Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Speed of Boolean equality operators
#!/usr/bin/perl
use strict;
use warnings;
use Time::HiRes;
my @tfs = map { $_ % 2 } (1 .. 10000);
# Just warming up the arrays
my $z;
foreach my $x (@tfs) {
foreach my $y (@tfs) {
$z = $x + $y;
}
}
my $start;
my $end;
$start = Time::HiRes::gettimeofday();
foreach my $x (@tfs) {
foreach my $y (@tfs) {
$z = !($x xor $y);
}
}
$end = Time::HiRes::gettimeofday();
printf("Exclusivity %.2f\n", $end - $start);
$start = Time::HiRes::gettimeofday();
foreach my $x (@tfs) {
foreach my $y (@tfs) {
$z = !$x == !$y;
}
}
$end = Time::HiRes::gettimeofday();
printf("Naysayers %.2f\n", $end - $start);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.