4 ms·
Trying to write fast c++ code is eye opening about how slow ram can be. Adding two number on the cpu is gonna take ~1 ns. Getting the number from ram takes abou
by maximus-decimus 5y ago
Trying to write fast c++ code is eye opening about how slow ram can be. Adding two number on the cpu is gonna take ~1 ns. Getting the number from ram takes about ~100 ns.
If you store your numbers sequentially in memory, you can bulk download them and it isn't so bad. But let's say you used a linked list where everything is store in a different memory location... you're basically gonna take 100 longer to iterate over a linked list than an array and that's entirely because of ram speed. Same thing if you're storing Integer objects into an arraylist in Java or something similar since your array contains pointers and you have to check a new ram location for every number. Facebook wrote their own version of a C++ string to reduce heap use because of this.
What I'm saying is you can often get around it for stuff that matters, but a lot of code that wasn't written with that in mind is definitely limited by ram speed. And let's be honest, most people who are not programming in C or C++ don't think about RAM data locality.