StringBuilder is slower than string concat? #2794
Unanswered
zoilorys
asked this question in
Questions & support
Replies: 1 comment
-
Hello! Here's some docs on building binaries (strings and bit arrays) https://www.erlang.org/doc/efficiency_guide/binaryhandling#constructing-binaries The string builder (an iolist in Erlang terms) is best for when you need to prepend as well as append, when you have large sub-binaries, and when you want to write the data directly to a socket or file rather than turning it into a string as there is no copying at all in this case. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone,
I was experimenting with Gleam and I was doing a lot of HTML string concatenation, so I rewrote logic to string builder. And just for fun decided to try and benchmark how much faster code become in comparison to initial version, so I used Glychee to test it out and to my surprise code actually become slower.
So I created synthetic test with huge number of concatenations and here are the results.
So, the code I used for testing:
And here are the results

Am I getting something wrong? Maybe there is a better way to use string builder for huge number of concatenations?
Beta Was this translation helpful? Give feedback.
All reactions