in reply to Re^3: Is there something faster than string concatenation? (hermit crabs)
in thread Is there something faster than string concatenation?
While trying to post a snippet that would demonstrate the doubling of the buffer size, I found that I can only account for an addition of at most 3 bytes more than needed.
use Devel::Size qw( size ); my $s = ''; for (0..1024*1024) { printf("%2d %3d\n", length($s), size($s)); $s .= 'a'; }
... 1048563 1048588 1048564 1048592 1048565 1048592 1048566 1048592 1048567 1048592 1048568 1048596 1048569 1048596 1048570 1048596 1048571 1048596 1048572 1048600 1048573 1048600 1048574 1048600 1048575 1048600 1048576 1048604
It allocates the nearest divisible by 4 amount.
Similar results when appending more than one byte.
Devel::Peek concurs.
ActivePerl 5.8.8 on WinXP.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Is there something faster than string concatenation? (hermit crabs)
by eyepopslikeamosquito (Archbishop) on Dec 03, 2007 at 11:23 UTC | |
by tye (Sage) on Dec 03, 2007 at 19:21 UTC | |
by Joost (Canon) on Dec 03, 2007 at 12:59 UTC |