Why using `+=` instead of `=` generates slow code?

Note that you didn’t really benchmark the same stuff in your original code: If you update v via +=, the ranges where sin and cos are called increase over time. I think this might be one problem you observe. This is reduced by using the setup keyword argument of @benchmark.

6 Likes