> ... code like (1..100_000).to_seq.map is simply bad, sorry.

Hmmm, I have different view on performance.

That code would produce ~x2 memory and ~x1-4 lower speed compared to plain 
for-loop/iterators/macros etc. But, it won't change the complexity class, it's 
`O(n)` now, and the fastest possible version with `for-loop` will be also 
`O(n)`.

Is it bad? For some low-level library functions or hot-spot code - yes, it 
would be bad.

Is it bad in our example? - No, change it and the overal speed improve maybe by 
1% or even less.

Is it bad for like 95% of codebase of 95% of applications? I would say no. Make 
it faster - maybe in some really badly written software we'll notice some 
improvements, but most probably nobody notices the difference.

Now let's look at the really bad code. The lack of Copy-on-Memory turned code 
that on the surfice appears to be `O(n)` into totally different complexity 
class `0(n^2)` \- and, it's a hot-spot code.
    
    
    proc get_prices: seq[float] = prices
    for _ in 1..100_000:
      discard get_prices()[2]
    
    
    Run

What's the point of optimizing 1) "non hot spot, O(n)" code, when we have a 2) 
"hot spot, O(n^2)" code?

If we consider performance - we should start with the second part, that's 
where's the real problem - part N2.

Reply via email to