Making reasonable use of computer resources

4 pointsposted 15 hours ago
by fanf2

1 Comments

chrisjj

15 hours ago

> A simple program that shows what a massive impact good cache usage can have on performance is to sum the elements of a matrix row-by-row vs. column-by-column (here’s a Rust Playground link that demonstrates this). In this example, the row-by-row is about 12–16 times faster than the column-by-column, even though they have same Big-O complexity. The difference in performance is not due to an abstract, computer science factor, but due to a very concrete one: better use of the CPU cache. The row-by-row approach brings 16 floats in cache and uses them all before going back to memory; by contrast the column-by-column approach also brings 16 floats

This overlooks that this result is a consequence of the compiler's totally arbitrary favouring of by-row in array storage.