in reply to Re^4: Is there something faster than string concatenation? (hermit crabs)
in thread Is there something faster than string concatenation?
I see the same result on Linux. However, stepping through the C code in the debugger indicates it passes repeatedly through Perl_pp_concat (pp_hot.c) and Perl_sv_grow (sv.c) and in Perl_sv_grow() it calls realloc here:
So it seems the performance of Perl string concatenation depends on the performance of the underlying C library realloc function. Now, I thought most reallocs would double the string size (for the reasons pointed out earlier by tye) so I'm a bit confused about the Devel::Size results. Haven't resorted to studying the glibc realloc code yet.if (newlen > SvLEN(sv)) { /* need more room? */ newlen = PERL_STRLEN_ROUNDUP(newlen); if (SvLEN(sv) && s) { #ifdef MYMALLOC const STRLEN l = malloced_size((void*)SvPVX_const(sv)); if (newlen <= l) { SvLEN_set(sv, l); return s; } else #endif s = saferealloc(s, newlen);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^6: Is there something faster than string concatenation? (quantum shells)
by tye (Sage) on Dec 03, 2007 at 19:21 UTC | |
Re^6: Is there something faster than string concatenation? (hermit crabs)
by Joost (Canon) on Dec 03, 2007 at 12:59 UTC |