]> Sergey Matveev's repositories - public-inbox.git/commit
ds: cleanup Errno imports and favor constant comparisons
authorEric Wong <e@80x24.org>
Mon, 3 Jun 2019 09:11:00 +0000 (09:11 +0000)
committerEric Wong <e@80x24.org>
Mon, 10 Jun 2019 05:05:15 +0000 (05:05 +0000)
commit6fa2b29fcd0477d126ebb7db7f97b334f74bbcbc
tree898548943442cd3b9e0ec8ebf986052b2b2fd2e9
parent42bb1574bf35a18f037d4ca8b0e6696192d301df
ds: cleanup Errno imports and favor constant comparisons

Stop importing unused constants, and favor integer comparisons
of `$!' over `$!{EFOO}' hash lookups.  Integer comparisons are
slightly faster, even:

Benchmark: timing 30 iterations of cmp_eq, cmp_ne, hash_hit, hash_miss...
    cmp_eq:  1 wallclock secs ( 1.61 usr +  0.00 sys =  1.61 CPU) @ 18.63/s (n=30)
    cmp_ne:  2 wallclock secs ( 1.57 usr +  0.00 sys =  1.57 CPU) @ 19.11/s (n=30)
  hash_hit:  4 wallclock secs ( 3.85 usr +  0.00 sys =  3.85 CPU) @  7.79/s (n=30)
 hash_miss:  4 wallclock secs ( 3.74 usr +  0.00 sys =  3.74 CPU) @  8.02/s (n=30)

#!/usr/bin/perl -w
use Benchmark qw(:all);
use Errno qw(EAGAIN EINTR);
my ($r, $w);
pipe($r, $w) or die 'pipe';
require IO::Handle;
$r->blocking(0);
my $buf;
my $n = 30000;
timethese(30, {
hash_hit => sub {
sysread($r, $buf, 1);
for (0..$n) {
next if $!{EAGAIN};
die 'FAIL';
}
}
,
'cmp_eq' => sub {
sysread($r, $buf, 1);
for (0..$n) {
next if $! == EAGAIN;
die 'FAIL';
}
},
hash_miss => sub {
sysread($r, $buf, 1);
for (0..$n) {
die 'FAIL' if $!{EINTR};
}
},
'cmp_ne' => sub {
sysread($r, $buf, 1);
for (0..$n) {
die 'FAIL' if $! == EINTR;
}
},
});
lib/PublicInbox/DS.pm