in reply to performance of length() in utf-8
It seems to me that bigger is the string, longer is the time to get its size, (exponentialy?).Linearly. Perl_utf8_length is basically:
and UTF8SKIP just returns the number of bytes in a utf-8 encoded codepoint given the starting byte. So, basically, PL_utf8_length is O(N), where N is the number of codepoins in (SvUTF8) string.while (start_ptr < end_ptr) { start_ptr += UTF8SKIP(start_ptr); len++; }
Your LenTestA is exponential because it basically does
while LenTestB isPL_utf8_length($chunk) # first iteration PL_utf8_length($chunk . $chunk) # second iteration PL_utf8_length($chunk . $chunk . $chunk) # third iteration ...and so on...
PL_utf8_length($chunk) # 1st PL_utf8_length($chunk) # 2nd PL_utf8_length($chunk) # 3rd ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: performance of length() in utf-8
by kennethk (Abbot) on Mar 03, 2016 at 20:38 UTC | |
by Anonymous Monk on Mar 03, 2016 at 20:46 UTC | |
by kennethk (Abbot) on Mar 03, 2016 at 21:49 UTC | |
by SuicideJunkie (Vicar) on Mar 03, 2016 at 21:51 UTC |