in reply to Why is using binmode on a file handle 77 times slower than just closing it and re-opening?
Try appending the following line to your test:
And then try to count how many times the string encoding(utf-8-strict)utf8repeats. In my case, it was 922 ×warn PerlIO::get_layers($handle{$file});
my @l = grep /utf-?8/, PerlIO::get_layers($handle{$file}); warn @l / 2;
To fix that, clear the layers before applying new ones by starting with :raw:
The result becomes agreeable:binmode $fh, ':raw:encoding(UTF-8)';
And the warning now shows a pretty low number.Rate close noclose close 2137/s -- -28% noclose 2951/s 38% --
Updated: Show how to count the repeated layers.
Update 2: On MSWin, you might need to add :crlf after :raw if needed, too.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Why is using binmode on a file handle 77 times slower than just closing it and re-opening?
by Maelstrom (Beadle) on Nov 25, 2024 at 09:00 UTC |