This is a benchmark of the proposed new utf8 encoding strategy for node.js. The main reason for this is that node needs to have its "own" utf-8 encoder that properly handles surrogate pairs.
new
- Uses the proposed new utf8 encoder andv8::String::Memory
api.old_nohint
- Usesv8::String::WriteUTF8
without the HINT_MANY_WRITES_EXPECTED flag.old_hint
- Usesv8::String::WriteUTF8
with the HINT_MANY_WRITES_EXPECTED flag. This means that v8 will try to flatten the string before writing. That means that most likely it will look much better than it is in reality, because typical applications don't convert the same string over and over again. This benchmark however does.
shape: flat
- produced bys = some_buffer.toString()
shape: left-tailed
- produced by repeatedly runnings = 'abcdefgh' + s;
shape: right-tailed
- produced by repeatedly runnings = s + 'abcdefgh';
shape: tree
- produced by repeatedly runnings = s + s;
ascii
- string contains only ascii characterssingle nonascii
- string contains exactly one non-ascii charactermixed
- string contains many non-ascii characters
- When the string contains only ascii characters the old encoder is unbeatable.
- As soon as unicode characters appear, the new encoder is faster.
- When the string grows beyond 10k and the string contains any non-ascii character, v8's performance becomes extremely bad.
size: 8, shape: left_tailed, content: ascii, iterations: 10000000
new: 2.412 s old_nohint: 1.877 s old_hint: 1.907 s
size: 8, shape: left_tailed, content: single nonascii, iterations: 10000000
new: 2.931 s old_nohint: 3.084 s old_hint: 3.085 s
size: 8, shape: left_tailed, content: mixed, iterations: 10000000
new: 2.89 s old_nohint: 3.008 s old_hint: 3.067 s
size: 8, shape: right_tailed, content: ascii, iterations: 10000000
new: 2.164 s old_nohint: 1.89 s old_hint: 1.9 s
size: 8, shape: right_tailed, content: single nonascii, iterations: 10000000
new: 2.876 s old_nohint: 3.005 s old_hint: 3.057 s
size: 8, shape: right_tailed, content: mixed, iterations: 10000000
new: 2.878 s old_nohint: 3.001 s old_hint: 3.075 s
size: 16, shape: tree, content: ascii, iterations: 10000000
new: 2.251 s old_nohint: 2.018 s old_hint: 2.032 s
size: 16, shape: tree, content: single nonascii, iterations: 10000000
new: 3.152 s old_nohint: 3.924 s old_hint: 4.209 s
size: 16, shape: tree, content: mixed, iterations: 10000000
new: 3.457 s old_nohint: 4.474 s old_hint: 4.295 s
size: 16, shape: flat, content: ascii, iterations: 10000000
new: 2.122 s old_nohint: 1.877 s old_hint: 1.885 s
size: 16, shape: flat, content: single nonascii, iterations: 10000000
new: 3.149 s old_nohint: 3.957 s old_hint: 4.017 s
size: 16, shape: flat, content: mixed, iterations: 10000000
new: 3.205 s old_nohint: 3.988 s old_hint: 4.036 s
size: 64, shape: left_tailed, content: ascii, iterations: 5000000
new: 1.532 s old_nohint: 2.247 s old_hint: 2.246 s
size: 64, shape: left_tailed, content: single nonascii, iterations: 5000000
new: 2.303 s old_nohint: 5.103 s old_hint: 5.152 s
size: 64, shape: left_tailed, content: mixed, iterations: 5000000
new: 3.548 s old_nohint: 6.974 s old_hint: 5.295 s
size: 64, shape: right_tailed, content: ascii, iterations: 5000000
new: 1.621 s old_nohint: 1.409 s old_hint: 1.418 s
size: 64, shape: right_tailed, content: single nonascii, iterations: 5000000
new: 2.514 s old_nohint: 5.286 s old_hint: 5.104 s
size: 64, shape: right_tailed, content: mixed, iterations: 5000000
new: 3.609 s old_nohint: 7.14 s old_hint: 5.289 s
size: 72, shape: tree, content: ascii, iterations: 5000000
new: 1.717 s old_nohint: 1.9 s old_hint: 1.903 s
size: 72, shape: tree, content: single nonascii, iterations: 5000000
new: 2.647 s old_nohint: 5.044 s old_hint: 5.575 s
size: 72, shape: tree, content: mixed, iterations: 5000000
new: 3.98 s old_nohint: 8.452 s old_hint: 6.022 s
size: 72, shape: flat, content: ascii, iterations: 5000000
new: 1.12 s old_nohint: 0.97 s old_hint: 0.974 s
size: 72, shape: flat, content: single nonascii, iterations: 5000000
new: 2.345 s old_nohint: 5.43 s old_hint: 5.475 s
size: 72, shape: flat, content: mixed, iterations: 5000000
new: 2.813 s old_nohint: 5.593 s old_hint: 5.652 s
size: 512, shape: left_tailed, content: ascii, iterations: 1000000
new: 1.069 s old_nohint: 2.809 s old_hint: 2.81 s
size: 512, shape: left_tailed, content: single nonascii, iterations: 1000000
new: 1.843 s old_nohint: 6.107 s old_hint: 6.48 s
size: 512, shape: left_tailed, content: mixed, iterations: 1000000
new: 3.87 s old_nohint: 9.05 s old_hint: 6.822 s
size: 512, shape: right_tailed, content: ascii, iterations: 1000000
new: 1.274 s old_nohint: 1.026 s old_hint: 1.03 s
size: 512, shape: right_tailed, content: single nonascii, iterations: 1000000
new: 2.273 s old_nohint: 7.059 s old_hint: 6.473 s
size: 512, shape: right_tailed, content: mixed, iterations: 1000000
new: 4.21 s old_nohint: 9.97 s old_hint: 6.848 s
size: 520, shape: tree, content: ascii, iterations: 1000000
new: 1.356 s old_nohint: 2.32 s old_hint: 2.311 s
size: 520, shape: tree, content: single nonascii, iterations: 1000000
new: 2.446 s old_nohint: 6.144 s old_hint: 6.628 s
size: 520, shape: tree, content: mixed, iterations: 1000000
new: 4.829 s old_nohint: 11.454 s old_hint: 6.912 s
size: 520, shape: flat, content: ascii, iterations: 1000000
new: 0.318 s old_nohint: 0.209 s old_hint: 0.21 s
size: 520, shape: flat, content: single nonascii, iterations: 1000000
new: 1.549 s old_nohint: 6.583 s old_hint: 6.607 s
size: 520, shape: flat, content: mixed, iterations: 1000000
new: 2.616 s old_nohint: 6.89 s old_hint: 6.889 s
size: 4096, shape: left_tailed, content: ascii, iterations: 200000
new: 1.423 s old_nohint: 4.152 s old_hint: 4.158 s
size: 4096, shape: left_tailed, content: single nonascii, iterations: 200000
new: 2.504 s old_nohint: 9.505 s old_hint: 9.664 s
size: 4096, shape: left_tailed, content: mixed, iterations: 200000
new: 5.471 s old_nohint: 14.7 s old_hint: 10.109 s
size: 4096, shape: right_tailed, content: ascii, iterations: 200000
new: 1.719 s old_nohint: 1.399 s old_hint: 1.397 s
size: 4096, shape: right_tailed, content: single nonascii, iterations: 200000
new: 3.141 s old_nohint: 10.98 s old_hint: 9.683 s
size: 4096, shape: right_tailed, content: mixed, iterations: 200000
new: 6.218 s old_nohint: 17.037 s old_hint: 10.173 s
size: 4104, shape: tree, content: ascii, iterations: 200000
new: 1.885 s old_nohint: 3.441 s old_hint: 3.439 s
size: 4104, shape: tree, content: single nonascii, iterations: 200000
new: 3.377 s old_nohint: 8.822 s old_hint: 9.683 s
size: 4104, shape: tree, content: mixed, iterations: 200000
new: 6.881 s old_nohint: 17.913 s old_hint: 10.219 s
size: 4104, shape: flat, content: ascii, iterations: 200000
new: 0.209 s old_nohint: 0.072 s old_hint: 0.072 s
size: 4104, shape: flat, content: single nonascii, iterations: 200000
new: 2.053 s old_nohint: 9.686 s old_hint: 9.687 s
size: 4104, shape: flat, content: mixed, iterations: 200000
new: 3.449 s old_nohint: 10.207 s old_hint: 10.161 s
size: 32768, shape: left_tailed, content: ascii, iterations: 20000
new: 1.056 s old_nohint: 3.132 s old_hint: 3.131 s
size: 32768, shape: left_tailed, content: single nonascii, iterations: 20000
new: 1.897 s old_nohint: 10.655 s old_hint: 7.623 s
size: 32768, shape: left_tailed, content: mixed, iterations: 20000
new: 4.312 s old_nohint: 16.506 s old_hint: 8.181 s
size: 32768, shape: right_tailed, content: ascii, iterations: 20000
new: 1.42 s old_nohint: 1.082 s old_hint: 1.098 s
size: 32768, shape: right_tailed, content: single nonascii, iterations: 20000
new: 2.63 s old_nohint: 12.007 s old_hint: 7.608 s
size: 32768, shape: right_tailed, content: mixed, iterations: 20000
new: 5.074 s old_nohint: 18.602 s old_hint: 8.006 s
size: 32776, shape: tree, content: ascii, iterations: 20000
new: 1.428 s old_nohint: 2.692 s old_hint: 2.695 s
size: 32776, shape: tree, content: single nonascii, iterations: 20000
new: 2.58 s old_nohint: 6.889 s old_hint: 7.63 s
size: 32776, shape: tree, content: mixed, iterations: 20000
new: 5.359 s old_nohint: 14.128 s old_hint: 8.015 s
size: 32776, shape: flat, content: ascii, iterations: 20000
new: 0.142 s old_nohint: 0.046 s old_hint: 0.045 s
size: 32776, shape: flat, content: single nonascii, iterations: 20000
new: 1.567 s old_nohint: 7.606 s old_hint: 7.613 s
size: 32776, shape: flat, content: mixed, iterations: 20000
new: 2.681 s old_nohint: 8.009 s old_hint: 8.013 s
size: 262144, shape: left_tailed, content: ascii, iterations: 2000
new: 0.827 s old_nohint: 2.075 s old_hint: 2.042 s
size: 262144, shape: left_tailed, content: single nonascii, iterations: 2000
new: 1.498 s old_nohint: 29.098 s old_hint: 6.067 s
size: 262144, shape: left_tailed, content: mixed, iterations: 2000
new: 3.429 s old_nohint: 43.923 s old_hint: 6.374 s
size: 262144, shape: right_tailed, content: ascii, iterations: 2000
new: 1.124 s old_nohint: 0.85 s old_hint: 0.853 s
size: 262144, shape: right_tailed, content: single nonascii, iterations: 2000
new: 2.095 s old_nohint: 30.873 s old_hint: 6.07 s
size: 262144, shape: right_tailed, content: mixed, iterations: 2000
new: 4.075 s old_nohint: 46.872 s old_hint: 6.391 s
size: 262152, shape: tree, content: ascii, iterations: 2000
new: 1.124 s old_nohint: 2.154 s old_hint: 2.151 s
size: 262152, shape: tree, content: single nonascii, iterations: 2000
new: 2.046 s old_nohint: 5.537 s old_hint: 6.115 s
size: 262152, shape: tree, content: mixed, iterations: 2000
new: 4.267 s old_nohint: 11.451 s old_hint: 6.424 s
size: 262152, shape: flat, content: ascii, iterations: 2000
new: 0.105 s old_nohint: 0.047 s old_hint: 0.047 s
size: 262152, shape: flat, content: single nonascii, iterations: 2000
new: 1.234 s old_nohint: 6.079 s old_hint: 6.086 s
size: 262152, shape: flat, content: mixed, iterations: 2000
new: 2.133 s old_nohint: 6.417 s old_hint: 6.392 s
size: 2097152, shape: left_tailed, content: ascii, iterations: 300
new: 1.156 s old_nohint: 2.058 s old_hint: 2.051 s
size: 2097152, shape: left_tailed, content: single nonascii, iterations: 300
new: 1.991 s old_nohint: 241.691 s old_hint: 7.46 s
size: 2097152, shape: left_tailed, content: mixed, iterations: 300
new: 4.324 s old_nohint: ^C
size: 8, shape: left_tailed, content: ascii, iterations: 10000000
new: 2.113 s old_nohint: 1.848 s old_hint: 1.836 s
size: 8, shape: left_tailed, content: single nonascii, iterations: 10000000
new: 2.891 s old_nohint: 2.885 s old_hint: 2.916 s
size: 8, shape: left_tailed, content: mixed, iterations: 10000000
new: 2.888 s old_nohint: 2.88 s old_hint: 2.914 s
size: 8, shape: right_tailed, content: ascii, iterations: 10000000
new: 2.082 s old_nohint: 1.828 s old_hint: 1.83 s
size: 8, shape: right_tailed, content: single nonascii, iterations: 10000000
new: 2.886 s old_nohint: 2.877 s old_hint: 2.91 s
size: 8, shape: right_tailed, content: mixed, iterations: 10000000
new: 2.895 s old_nohint: 2.872 s old_hint: 2.915 s
size: 16, shape: tree, content: ascii, iterations: 10000000
new: 2.229 s old_nohint: 1.979 s old_hint: 1.972 s
size: 16, shape: tree, content: single nonascii, iterations: 10000000
new: 3.165 s old_nohint: 3.724 s old_hint: 3.937 s
size: 16, shape: tree, content: mixed, iterations: 10000000
new: 3.554 s old_nohint: 4.253 s old_hint: 3.984 s
size: 16, shape: flat, content: ascii, iterations: 10000000
new: 2.105 s old_nohint: 1.842 s old_hint: 1.834 s
size: 16, shape: flat, content: single nonascii, iterations: 10000000
new: 3.255 s old_nohint: 3.714 s old_hint: 3.751 s
size: 16, shape: flat, content: mixed, iterations: 10000000
new: 3.311 s old_nohint: 3.751 s old_hint: 3.809 s
size: 64, shape: left_tailed, content: ascii, iterations: 5000000
new: 1.51 s old_nohint: 1.552 s old_hint: 1.543 s
size: 64, shape: left_tailed, content: single nonascii, iterations: 5000000
new: 2.286 s old_nohint: 4.86 s old_hint: 4.798 s
size: 64, shape: left_tailed, content: mixed, iterations: 5000000
new: 3.783 s old_nohint: 6.482 s old_hint: 4.955 s
size: 64, shape: right_tailed, content: ascii, iterations: 5000000
new: 1.585 s old_nohint: 1.381 s old_hint: 1.386 s
size: 64, shape: right_tailed, content: single nonascii, iterations: 5000000
new: 2.472 s old_nohint: 5.051 s old_hint: 4.713 s
size: 64, shape: right_tailed, content: mixed, iterations: 5000000
new: 3.865 s old_nohint: 6.583 s old_hint: 4.963 s
size: 72, shape: tree, content: ascii, iterations: 5000000
new: 1.746 s old_nohint: 2.115 s old_hint: 2.119 s
size: 72, shape: tree, content: single nonascii, iterations: 5000000
new: 2.606 s old_nohint: 5.054 s old_hint: 5.193 s
size: 72, shape: tree, content: mixed, iterations: 5000000
new: 4.684 s old_nohint: 8.018 s old_hint: 5.321 s
size: 72, shape: flat, content: ascii, iterations: 5000000
new: 1.147 s old_nohint: 0.961 s old_hint: 0.957 s
size: 72, shape: flat, content: single nonascii, iterations: 5000000
new: 2.568 s old_nohint: 5.058 s old_hint: 5.065 s
size: 72, shape: flat, content: mixed, iterations: 5000000
new: 3.2 s old_nohint: 5.236 s old_hint: 5.269 s
size: 512, shape: left_tailed, content: ascii, iterations: 1000000
new: 1.024 s old_nohint: 1.037 s old_hint: 1.031 s
size: 512, shape: left_tailed, content: single nonascii, iterations: 1000000
new: 1.781 s old_nohint: 5.952 s old_hint: 6.138 s
size: 512, shape: left_tailed, content: mixed, iterations: 1000000
new: 4.439 s old_nohint: 8.472 s old_hint: 6.456 s
size: 512, shape: right_tailed, content: ascii, iterations: 1000000
new: 1.196 s old_nohint: 1.007 s old_hint: 1.007 s
size: 512, shape: right_tailed, content: single nonascii, iterations: 1000000
new: 2.152 s old_nohint: 6.821 s old_hint: 6.119 s
size: 512, shape: right_tailed, content: mixed, iterations: 1000000
new: 5.146 s old_nohint: 9.494 s old_hint: 6.495 s
size: 520, shape: tree, content: ascii, iterations: 1000000
new: 1.288 s old_nohint: 2.667 s old_hint: 2.691 s
size: 520, shape: tree, content: single nonascii, iterations: 1000000
new: 2.214 s old_nohint: 5.938 s old_hint: 6.269 s
size: 520, shape: tree, content: mixed, iterations: 1000000
new: 5.62 s old_nohint: 11.128 s old_hint: 6.544 s
size: 520, shape: flat, content: ascii, iterations: 1000000
new: 0.33 s old_nohint: 0.208 s old_hint: 0.207 s
size: 520, shape: flat, content: single nonascii, iterations: 1000000
new: 1.946 s old_nohint: 6.229 s old_hint: 6.244 s
size: 520, shape: flat, content: mixed, iterations: 1000000
new: 3.061 s old_nohint: 6.471 s old_hint: 6.458 s
size: 4096, shape: left_tailed, content: ascii, iterations: 200000
new: 1.44 s old_nohint: 1.422 s old_hint: 1.42 s
size: 4096, shape: left_tailed, content: single nonascii, iterations: 200000
new: 2.457 s old_nohint: 9.232 s old_hint: 9.214 s
size: 4096, shape: left_tailed, content: mixed, iterations: 200000
new: 6.527 s old_nohint: 13.933 s old_hint: 9.669 s
size: 4096, shape: right_tailed, content: ascii, iterations: 200000
new: 1.643 s old_nohint: 1.435 s old_hint: 1.442 s
size: 4096, shape: right_tailed, content: single nonascii, iterations: 200000
new: 2.966 s old_nohint: 10.505 s old_hint: 9.194 s
size: 4096, shape: right_tailed, content: mixed, iterations: 200000
new: 7.051 s old_nohint: 16.332 s old_hint: 9.693 s
size: 4104, shape: tree, content: ascii, iterations: 200000
new: 1.784 s old_nohint: 4.177 s old_hint: 4.165 s
size: 4104, shape: tree, content: single nonascii, iterations: 200000
new: 3.233 s old_nohint: 8.568 s old_hint: 9.235 s
size: 4104, shape: tree, content: mixed, iterations: 200000
new: 7.538 s old_nohint: 17.256 s old_hint: 9.73 s
size: 4104, shape: flat, content: ascii, iterations: 200000
new: 0.208 s old_nohint: 0.07 s old_hint: 0.07 s
size: 4104, shape: flat, content: single nonascii, iterations: 200000
new: 2.703 s old_nohint: 9.203 s old_hint: 9.217 s
size: 4104, shape: flat, content: mixed, iterations: 200000
new: 4.456 s old_nohint: 9.704 s old_hint: 9.71 s
size: 32768, shape: left_tailed, content: ascii, iterations: 20000
new: 1.05 s old_nohint: 1.077 s old_hint: 1.079 s
size: 32768, shape: left_tailed, content: single nonascii, iterations: 20000
new: 1.883 s old_nohint: 10.275 s old_hint: 7.161 s
size: 32768, shape: left_tailed, content: mixed, iterations: 20000
new: 5.037 s old_nohint: 15.538 s old_hint: 7.586 s
size: 32768, shape: right_tailed, content: ascii, iterations: 20000
new: 1.362 s old_nohint: 1.074 s old_hint: 1.075 s
size: 32768, shape: right_tailed, content: single nonascii, iterations: 20000
new: 2.46 s old_nohint: 11.396 s old_hint: 7.152 s
size: 32768, shape: right_tailed, content: mixed, iterations: 20000
new: 5.492 s old_nohint: 17.714 s old_hint: 7.58 s
size: 32776, shape: tree, content: ascii, iterations: 20000
new: 1.384 s old_nohint: 3.238 s old_hint: 3.243 s
size: 32776, shape: tree, content: single nonascii, iterations: 20000
new: 2.465 s old_nohint: 6.664 s old_hint: 7.161 s
size: 32776, shape: tree, content: mixed, iterations: 20000
new: 5.826 s old_nohint: 13.516 s old_hint: 7.598 s
size: 32776, shape: flat, content: ascii, iterations: 20000
new: 0.147 s old_nohint: 0.045 s old_hint: 0.043 s
size: 32776, shape: flat, content: single nonascii, iterations: 20000
new: 2.049 s old_nohint: 7.129 s old_hint: 7.134 s
size: 32776, shape: flat, content: mixed, iterations: 20000
new: 3.492 s old_nohint: 7.598 s old_hint: 7.568 s
size: 262144, shape: left_tailed, content: ascii, iterations: 2000
new: 0.813 s old_nohint: 0.841 s old_hint: 0.837 s
size: 262144, shape: left_tailed, content: single nonascii, iterations: 2000
new: 1.459 s old_nohint: 27.958 s old_hint: 5.653 s
size: 262144, shape: left_tailed, content: mixed, iterations: 2000
new: 4.039 s old_nohint: 42.708 s old_hint: 6.165 s
size: 262144, shape: right_tailed, content: ascii, iterations: 2000
new: 1.091 s old_nohint: 0.843 s old_hint: 0.843 s
size: 262144, shape: right_tailed, content: single nonascii, iterations: 2000
new: 1.985 s old_nohint: 30.413 s old_hint: 5.675 s
size: 262144, shape: right_tailed, content: mixed, iterations: 2000
new: 4.348 s old_nohint: 45.028 s old_hint: 6.027 s
size: 262152, shape: tree, content: ascii, iterations: 2000
new: 1.066 s old_nohint: 2.539 s old_hint: 2.548 s
size: 262152, shape: tree, content: single nonascii, iterations: 2000
new: 1.927 s old_nohint: 5.271 s old_hint: 5.664 s
size: 262152, shape: tree, content: mixed, iterations: 2000
new: 4.579 s old_nohint: 10.792 s old_hint: 6.094 s
size: 262152, shape: flat, content: ascii, iterations: 2000
new: 0.105 s old_nohint: 0.046 s old_hint: 0.046 s
size: 262152, shape: flat, content: single nonascii, iterations: 2000
new: 1.599 s old_nohint: 5.624 s old_hint: 5.63 s
size: 262152, shape: flat, content: mixed, iterations: 2000
new: 2.73 s old_nohint: 6.052 s old_hint: 6.019 s
size: 2097152, shape: left_tailed, content: ascii, iterations: 300
new: 1.153 s old_nohint: 1.185 s old_hint: 1.189 s
size: 2097152, shape: left_tailed, content: single nonascii, iterations: 300
new: 1.964 s old_nohint: 233.748 s old_hint: 7.002 s
size: 2097152, shape: left_tailed, content: mixed, iterations: 300
new: 5.013 s old_nohint: 352.523 s old_hint: 7.452 s
size: 2097152, shape: right_tailed, content: ascii, iterations: 300
new: 1.49 s old_nohint: 1.179 s old_hint: 1.18 s
size: 2097152, shape: right_tailed, content: single nonascii, iterations: 300
new: 2.571 s old_nohint: 245.769 s old_hint: 6.971 s
size: 2097152, shape: right_tailed, content: mixed, iterations: 300
new: 5.483 s old_nohint: 362.439 s old_hint: 7.484 s
size: 2097160, shape: tree, content: ascii, iterations: 300
new: 1.411 s old_nohint: 3.17 s old_hint: 3.18 s
size: 2097160, shape: tree, content: single nonascii, iterations: 300
new: 2.437 s old_nohint: 6.448 s old_hint: 6.956 s
size: 2097160, shape: tree, content: mixed, iterations: 300
new: 5.677 s old_nohint: 13.35 s old_hint: 7.614 s
size: 2097160, shape: flat, content: ascii, iterations: 300
new: 0.254 s old_nohint: 0.21 s old_hint: 0.211 s
size: 2097160, shape: flat, content: single nonascii, iterations: 300
new: 2.1 s old_nohint: 7 s old_hint: 6.914 s
size: 2097160, shape: flat, content: mixed, iterations: 300
new: 3.469 s old_nohint: 7.463 s old_hint: 7.456 s
size: 16777216, shape: left_tailed, content: ascii, iterations: 40
new: 1.423 s old_nohint: 1.265 s old_hint: 1.262 s
size: 16777216, shape: left_tailed, content: single nonansi, iterations: 40
new: 2.109 s old_nohint: 2343.456 s old_hint: 7.837 s
size: 16777216, shape: left_tailed, content: mixed, iterations: 40
new: 5.547 s old_nohint: ^C