Get the latest tech news
Is Python Code Sensitive to CPU Caching? (2024)
-aware programming can make a huge performance difference, especially when writing code in C++ or Rust. Python is a much more high-level language, and doesn't give us that level of control over memory layout of our data structures.
I don't want to bother with strings and number parsing, so let's use Python's struct and array modules to pack the test data into a binary representation. Part of this is due to the lower amount of iterations, so that the initialization overhead (Python interpreter boot, parsing the input data) becomes more noticeable. That the pure-Python version suffered a greater slowdown could indicate that the more complex PyObject* layout is substantially more cache-hostile, but I have a hunch that this might not be the entire story, e.g. because these measurements also include input parsing overhead.
Or read this on Hacker News