9 ms·
normal arrays in bash are implemented as linked lists. bash stores a pointer to the last accessed element, which turns the most common case of iteration into O
by izabera 2y ago
normal arrays in bash are implemented as linked lists. bash stores a pointer to the last accessed element, which turns the most common case of iteration into O(1), but the performance is terrible if you need to jump around
see some basic benchmarks here
https://gist.github.com/izabera/16a46ed79c2248349a1fb83844686df3 https://gist.github.com/izabera/16a46ed79c2248349a1fb8384468...
there are also associative arrays which are bucketed hash tables, which are fine for string keys but imho they are hardly ever worth it as a replacement for indexed arrays
- anfractuosity 2y agoThanks a lot, that's very interesting re. it using linked lists, and nice benchmark!