I don't know much about Python but it seems strings are immutable. Meaning each 
time you add it allocates a new string with `len+1`, which explains why memory 
usage is about 100MB and its slow.

In Nim on the other hand strings are mutable. They are 
[resized](https://github.com/nim-lang/Nim/blob/devel/lib/system/seqs_v2.nim#L103)
 only when len+1 becames bigger than capacity. And the new cap is follows this 
[algo](https://github.com/nim-lang/Nim/blob/devel/lib/system/sysstr.nim#L25) 
Explains the extra space and why it's faster.

Reply via email to