In some code ported from Ruby I have
    
    
    grep "& @" ~/Router/router.nim
          lcuts = v.vertex.neighbors - (lcuts & @[u.vertex, w.vertex])
    
    
    
    Run

First I wrote lcuts & [u.vertex, w.vertex] but without the to seq operator it 
does not compile. I wondered why concatenation of an seq and an array is not 
supported. Of course typing the single @ in from of the array is not too much 
work, but the question is if that is optimized or if a whole seq is allocated. 
So I did a test:
    
    
    proc main =
      
      var s: seq[int]
      for i in 0 .. 1e5.int:
         #s.add(i)
        s = s & @[i]
      
      echo s[3] + s[^1]
    
    main()
    
    
    Run

While the program with add() takes milliseconds, it takes a few seconds with 
the seq. I would say that this is a serious performance trap not only for 
beginners. So maybe we should add concatenation of seq and array for std lib? 
Tested with option -d:danger of course.

Reply via email to