Thanks, I tried your fusedAppend template but it didn't work (compiled, but 
didn't change anything). I think for whatever reason it isn't getting used 
because I added echo a as a 2nd line and nothing was displayed.

It may be true that no one uses s = s + t (I doubt that), but if a 2-line 
template can change this into s &= t, I'd suggest it's worth adding that to the 
compiler for a 250x speed increase. This was a very unexpected speed bump to me.

Here's a test comparing s.add('x') with s &= 'x'. It seems like these should 
have identical performance, but: 
    
    
    ms:nim jim$ cat str1.nim
    var
      s: string
    
    for i in 0..100_000_000:
      s.add('x')
    echo len(s)
    
    ms:nim jim$ /usr/bin/time -l ./str1
    100000001
            0.88 real         0.73 user         0.14 sys
     440184832  maximum resident set size
        107485  page reclaims
             1  block output operations
             3  involuntary context switches
    
    ms:nim jim$ cat str1c.nim
    proc main() =
      var
        s: string
      
      for i in 0..100_000_000:
        s &= 'x'
      echo len(s)
    
    main()
    
    ms:nim jim$ nim c -d:danger str1c
    Hint: 14213 LOC; 0.587 sec; 16.016MiB peakmem; Dangerous Release build; 
proj: /Users/jim/nim/str1c; out: /User\
    s/jim/nim/str1c [SuccessX]
    
    ms:nim jim$ /usr/bin/time -l ./str1c
    100000001
            0.54 real         0.42 user         0.11 sys
     326619136  maximum resident set size
         79751  page reclaims
             8  page faults
             1  voluntary context switches
             5  involuntary context switches
    
    
    Run

Reply via email to