-
-
Save zoffixznet/2e7bfbc8de1eb21fc1cea3fc844ffc47 to your computer and use it in GitHub Desktop.
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
use lib </home/zoffix/CPANPRC/Benchy/lib>; | |
use Benchy; | |
augment class IO::Handle { | |
method getc2(IO::Handle:D:) { | |
$!decoder or die X::IO::BinaryMode.new(:trying<getc>); | |
$!decoder.consume-exactly-chars2(1) || self!getc-slow-path2() | |
} | |
method !getc-slow-path2() { | |
$!decoder.add-bytes(nqp::readfh($!PIO, buf8.new, 0x100000)); | |
$!decoder.consume-exactly-chars2(1) // $!decoder.consume-all-chars() || Nil | |
} | |
method getc3(IO::Handle:D:) { | |
$!decoder or die X::IO::BinaryMode.new(:trying<getc>); | |
$!decoder.consume-exactly-chars3(1) || self!getc-slow-path3() | |
} | |
method !getc-slow-path3() { | |
$!decoder.add-bytes(nqp::readfh($!PIO, buf8.new, 0x100000)); | |
$!decoder.consume-exactly-chars3(1) // $!decoder.consume-all-chars() || Nil | |
} | |
} | |
augment class Rakudo::Internals::VMBackedDecoder { | |
method consume-exactly-chars2(int $chars --> Str) { | |
my str $result = nqp::decodertakechars(self, $chars); | |
nqp::isnull_s($result) ?? Str !! $result | |
} | |
method consume-exactly-chars3(int $chars --> Str) { | |
nqp::ifnull(nqp::decodertakechars(self, $chars), Str); | |
} | |
} | |
my $f = $*TMPDIR.add('foo'); | |
$f.spurt: join "\n", 'a'..'z'; | |
b 5_000, | |
{ | |
my $fh = $f.open; | |
$ = $fh.getc2; $ = $fh.getc2; $ = $fh.getc2; $ = $fh.getc2; $ = $fh.getc2; | |
$ = $fh.getc2; $ = $fh.getc2; $ = $fh.getc2; $ = $fh.getc2; $ = $fh.getc2; | |
$ = $fh.getc2; $ = $fh.getc2; $ = $fh.getc2; $ = $fh.getc2; $ = $fh.getc2; | |
$ = $fh.getc2; $ = $fh.getc2; $ = $fh.getc2; $ = $fh.getc2; $ = $fh.getc2; | |
$ = $fh.getc2; $ = $fh.getc2; $ = $fh.getc2; $ = $fh.getc2; $ = $fh.getc2; | |
$ = $fh.getc2; $ = $fh.getc2; $ = $fh.getc2; $ = $fh.getc2; $ = $fh.getc2; | |
$ = $fh.getc2; $ = $fh.getc2; $ = $fh.getc2; $ = $fh.getc2; $ = $fh.getc2; | |
$ = $fh.getc2; $ = $fh.getc2; $ = $fh.getc2; $ = $fh.getc2; $ = $fh.getc2; | |
$fh.close; | |
}, | |
{ | |
my $fh = $f.open; | |
$ = $fh.getc3; $ = $fh.getc3; $ = $fh.getc3; $ = $fh.getc3; $ = $fh.getc3; | |
$ = $fh.getc3; $ = $fh.getc3; $ = $fh.getc3; $ = $fh.getc3; $ = $fh.getc3; | |
$ = $fh.getc3; $ = $fh.getc3; $ = $fh.getc3; $ = $fh.getc3; $ = $fh.getc3; | |
$ = $fh.getc3; $ = $fh.getc3; $ = $fh.getc3; $ = $fh.getc3; $ = $fh.getc3; | |
$ = $fh.getc3; $ = $fh.getc3; $ = $fh.getc3; $ = $fh.getc3; $ = $fh.getc3; | |
$ = $fh.getc3; $ = $fh.getc3; $ = $fh.getc3; $ = $fh.getc3; $ = $fh.getc3; | |
$ = $fh.getc3; $ = $fh.getc3; $ = $fh.getc3; $ = $fh.getc3; $ = $fh.getc3; | |
$ = $fh.getc3; $ = $fh.getc3; $ = $fh.getc3; $ = $fh.getc3; $ = $fh.getc3; | |
$fh.close; | |
}, | |
{ | |
my $fh = $f.open; | |
$ = $fh; $ = $fh; $ = $fh; $ = $fh; $ = $fh; | |
$ = $fh; $ = $fh; $ = $fh; $ = $fh; $ = $fh; | |
$ = $fh; $ = $fh; $ = $fh; $ = $fh; $ = $fh; | |
$ = $fh; $ = $fh; $ = $fh; $ = $fh; $ = $fh; | |
$ = $fh; $ = $fh; $ = $fh; $ = $fh; $ = $fh; | |
$ = $fh; $ = $fh; $ = $fh; $ = $fh; $ = $fh; | |
$ = $fh; $ = $fh; $ = $fh; $ = $fh; $ = $fh; | |
$ = $fh; $ = $fh; $ = $fh; $ = $fh; $ = $fh; | |
$fh.close; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment