News for hackers. Stuff that matters.
Re:Fun with Go Iterators by parhamn on Thursday October 10, 2024 @12:53PM (#41800790)
This isn't true outside the theoretical best case. Definitely not true in most interpreted languages. Consider the performance difference of .reverse() (in-place or copy) vs using a descending for loop. Generally with interpreter chaining there are more "hidden" allocations/operations.
Re:Fun with Go Iterators by tsimionescu on Friday October 11, 2024 @01:00AM (#41806326)
You're comparing apples and oranges. Of course modifying an array or copying it takes way more time than looping. The comparison was not about that, it's about one loop with 10 instructions VS 10 loops each with a single instruction, for the exact same instructions.
Re:Fun with Go Iterators by thrww120956 on Friday October 11, 2024 @04:57AM (#41807658)
There's no way to do this (a single instruction loop vs 10 loops with a single instruction) in JS or Golang.
Re:Fun with Go Iterators by tsimionescu on Friday October 11, 2024 @06:06AM (#41808036)
I don't mean assembly-level instructions, just general instructions in the language:

  for i := range arr {
    foo1(arr[i])
    ...
    foo10(arr[i])
  }
Vs

  for i := range arr {
    foo1(arr[i])
  }
  ... 
  for i := range arr {
    foo10(arr[i])
  }