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 ...
In reply to Re: performance of length() in utf-8
by Anonymous Monk
in thread performance of length() in utf-8
by seki
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |