3 ms·
.each_codepoint.size is more efficient than .codepoints.size, as it creates a sized Enumerator that avoids needing to build an intermediate Array. For strings
by Freaky 3y ago
.each_codepoint.size is more efficient than .codepoints.size, as it creates a sized Enumerator that avoids needing to build an intermediate Array. For strings with only single-byte characters it reduces to returning the already-stored stored byte length.
Same goes for .each_byte.size, but for that you have the faster .bytesize method that avoids the intermediate Enumerator.