4 ms·
The advice is quite broad and simplified, but I think the one caveat of writing "sometimes" is enough. What I mean is that, although the operating system cache
by jakobnissen 5y ago
The advice is quite broad and simplified, but I think the one caveat of writing "sometimes" is enough.
What I mean is that, although the operating system caches files in RAM, and some (but not all) languages like Python and Julia implements a cache in its abstraction over file reading, these caches are not as fast as simply loading a bunch of bytes into an array and reading from the array, because they are hidden behind an abstracted IO, and the abstraction is not zero-overhead.
The difference is especially noticable when you read byte-by-byte, as in the issue I linked to in the text. For example, if you try to implement parsing with a finite state machine reading one byte at a time, you basically need to access memory directly without any overhead.
It's possible there are IO abstractions where reading from a "file" in RAM is just as fast as loading a byte from memory, but I don't know of any such abstractions.