Today I'm comparing string operations with Nim 1.2.1 vs Python. This test
concatenates a letter to a string 1M times.
ms:nim jim$ cat str1a.nim
var
s: string
for i in 0..1_000_000:
s = s & 'x'
echo len(s)
ms:nim jim$ nim c -d:danger str1a
Hint: 14210 LOC; 0.565 sec; 16.02MiB peakmem; Dangerous Release build;
proj: /Users/jim/nim/str1a; out: /Users/jim/nim/str1a [SuccessX]
ms:nim jim$ /usr/bin/time -l ./str1a
1000001
45.02 real 44.98 user 0.03 sys
48394240 maximum resident set size
11825 page reclaims
8 page faults
1 voluntary context switches
16 involuntary context switches
ms:nim jim$ cat str1a.py
s = ''
for i in xrange(1000000):
s = s + 'x'
print len(s)
ms:nim jim$ /usr/bin/time -l py str1a.py
1000000
0.22 real 0.21 user 0.00 sys
6078464 maximum resident set size
1686 page reclaims
11 involuntary context switches
Run
I tried enclosing the Nim test with a proc. That did reduce RAM from 48.4M to
46M, but runtime was still 45s.