I've found PERL_NEW_COPY_ON_WRITE option at https://metacpan.org/module/DAGOLDEN/perl-5.19.1/pod/perldelta.pod#Performance-Enhancements
This feature was already available in 5.18.0, but wasn't enabled by default.
So I recompiled Perl 5.18.0 with PERL_NEW_COPY_ON_WRITE option on Windows and compared with Non-PERL_NEW_COPY_ON_WRITE Strawberry Perl 5.18.0.
This is the result.
<Test code>
perl -MBenchmark=cmpthese -e "sub A {my ($s) = @_; length($s) } sub B { my ($s) = @_; $s .= 'B'; length($s) } cmpthese(10000, { test1 => sub { my $s = 'A'x1000000; A($s) }, test2 => sub { my $s = 'A'x1000000; B($s) } })"
"sub A" doesn't modify the input string but "sub B" modfies the input string.
* Strawberry Perl 5.18.0
test1 3374/s -- -2%
test2 3428/s 2% --
* PERL_NEW_COPY_ON_WRITE version
test1 8905/s 539% --
test2 1393/s -- -84%
PERL_NEW_COPY_ON_WRITE option accelerates "sub A" but slows down "sub B".
I'm wondering why "sub B" is much slower in PERL_NEW_COPY_ON_WRITE option.
댓글 없음:
댓글 쓰기