5 ms·
This isn't true outside the theoretical best case. Definitely not true in most interpreted languages. Consider the performance difference of .reverse() (in-plac
by parhamn 2y ago
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.
- tsimionescu 2y agoYou'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.
- thrww120956 2y agoThere's no way to do this (a single instruction loop vs 10 loops with a single instruction) in JS or Golang.
- tsimionescu 2y agoI 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]) }