Remix.run Logo
fifilura 10 hours ago

Doing Python or R right means using vector/matrix operations in e.g. numpy. Those will be faster.

Just think twice before using a for loop. Most of the time it is not needed.

nickforr 7 hours ago | parent | next [-]

If you write the R code using vectorised operations it’s significant orders of magnitude faster (148 seconds to 1.5 milliseconds on posit.cloud).

The nested loop becomes: j <- sum((seq_len(100000) - 1) %% u) a <- a + j + r

MooseBurger 10 hours ago | parent | prev [-]

I disagree w.r.t. python. You shouldn't need a numerical computing library to do a for loop generally.

fifilura 9 hours ago | parent | next [-]

Kick the habit. For loops are what "goto" was 20 years ago. Error prone and not possible to abstract for example for parallel execution.

hatthew 7 hours ago | parent [-]

I think the comparison to goto is a little extreme, but actually not too crazy. I could see a future where the accepted best practice is to use parallelized operations for everything, and only use sequential loops in cases where the underlying concept is inherently sequential (gradient descent, iterative hashing, etc.).

9 hours ago | parent | prev [-]
[deleted]