This might be because indexing allocates memory, but it’s hard to tell for sure since you seem to be benchmarking in the global scope which causes problems.
Related topics
| Topic | Replies | Views | Activity | |
|---|---|---|---|---|
| Why fewer memory allocations does not necessarily suggest higher speed | 5 | 849 | June 6, 2021 | |
| Performance vs # of Alloc Unintuitive behavior | 11 | 395 | December 3, 2025 | |
| Migrating code from Matlab: Accessing arrays without allocating | 20 | 2071 | November 19, 2018 | |
| Memory allocation and usage of dot notation | 6 | 456 | October 19, 2022 | |
| Allocations and time of running the same program twice are orders of magnitude larger than running them separately | 11 | 760 | June 17, 2024 |