Created
February 1, 2015 15:59
-
-
Save andrewsolomon/3c0a1e0b998ab9d911b8 to your computer and use it in GitHub Desktop.
Speed of Boolean equality operators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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