3 ms·
Benchmarking strings is often benchmarking memory allocation speed or the GC. If you manipulate strings day in day out in your workflow, the first thing you do
by mratsim 6y ago
Benchmarking strings is often benchmarking memory allocation speed or the GC.
If you manipulate strings day in day out in your workflow, the first thing you do is remove all those allocations and for what is left you use a memory pool.
The speedup could easily go into the 20x in any language. It's actually one of the area where Python or JS can beat statically typed languages, they focused a lot into optimizing strings while statically typed languages often leave that as an exercise to the reader.
- throwaway894345 6y ago> It's actually one of the area where Python or JS can beat statically typed languages, they focused a lot into optimizing strings while statically typed languages often leave that as an exercise to the reader. I think this has more to do with writing the string handling functions in heavily-optimized C rather than in Python/JS than it does with memory tricks, but I'll happily accept correction.
- totalperspectiv 6y agoThe article linked is doing much more than benchmarking string operations. I'd even argue that string allocations are about as minimal as possible with the algorithms used. The C version takes this a little farther, but each of the other implementations are pretty similar. I don't disagree that benchmarks should be taken with a mound of salt though.