<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>benchmarking on Kai Striega</title><link>http://kaistriega.com/tags/benchmarking/</link><description>Recent content in benchmarking on Kai Striega</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Sun, 26 Jul 2026 11:20:00 +1000</lastBuildDate><atom:link href="http://kaistriega.com/tags/benchmarking/index.xml" rel="self" type="application/rss+xml"/><item><title>Pointer Chasing</title><link>http://kaistriega.com/blog/mechanical-sympathy/pointer-chasing/</link><pubDate>Sun, 26 Jul 2026 11:20:00 +1000</pubDate><guid>http://kaistriega.com/blog/mechanical-sympathy/pointer-chasing/</guid><description>&lt;p&gt;Everyone who writes Python for a living has been handed the same rule: don&amp;rsquo;t use a &lt;code&gt;list&lt;/code&gt;, use an array.
It&amp;rsquo;s a good rule. I&amp;rsquo;ve given it as advice myself, probably to someone who deserved a better explanation than
the one I gave.&lt;/p&gt;
&lt;p&gt;Here is the rule being followed, on two million integers:&lt;/p&gt;


&lt;div class="highlight"&gt;
 &lt;pre class="chroma"&gt;&lt;code&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;sum(values) &lt;span style="color:#75715e"&gt;# a plain list 10.0 ms&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;sum(values) &lt;span style="color:#75715e"&gt;# array(&amp;#39;q&amp;#39;) 19.2 ms&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Swapping the list for a compact array of machine integers made it &lt;strong&gt;twice as slow&lt;/strong&gt;. Nothing was measured
wrongly. That is what the machine does.&lt;/p&gt;</description></item><item><title>False Sharing</title><link>http://kaistriega.com/blog/mechanical-sympathy/false-sharing/</link><pubDate>Sat, 25 Jul 2026 14:01:54 +1000</pubDate><guid>http://kaistriega.com/blog/mechanical-sympathy/false-sharing/</guid><description>&lt;p&gt;&lt;a href="https://kaistriega.com/blog/mechanical-sympathy/array-of-structs-vs-struct-of-arrays/"&gt;Part one&lt;/a&gt; of this series had one central fact and one piece of advice. The fact was that memory moves
in 64 byte cache lines, so the cost of a loop is the number of lines it touches. The advice that fell out of
it was to pack your data tightly, because packing more useful bytes into each line means fetching fewer lines.&lt;/p&gt;
&lt;p&gt;This post is about a case where packing tightly is the entire bug, and the fix is to deliberately waste 56
bytes out of every 64.&lt;/p&gt;</description></item><item><title>Branch Prediction</title><link>http://kaistriega.com/blog/mechanical-sympathy/branch-prediction/</link><pubDate>Sat, 25 Jul 2026 11:45:58 +1000</pubDate><guid>http://kaistriega.com/blog/mechanical-sympathy/branch-prediction/</guid><description>&lt;p&gt;&lt;a href="https://kaistriega.com/blog/mechanical-sympathy/array-of-structs-vs-struct-of-arrays/"&gt;Last time&lt;/a&gt; I argued that your data layout is your program, because the machine reads memory in 64 byte
cache lines whether you asked for 64 bytes or 4. That post was about the CPU doing something &lt;em&gt;less&lt;/em&gt; than you
expected: it can only fetch whole lines, so a lot of what it fetches is wasted.&lt;/p&gt;
&lt;p&gt;This one is about the CPU doing something considerably stranger. It runs your code before it knows whether it
should.&lt;/p&gt;</description></item><item><title>Array of Structs vs Struct of Arrays</title><link>http://kaistriega.com/blog/mechanical-sympathy/array-of-structs-vs-struct-of-arrays/</link><pubDate>Sat, 25 Jul 2026 08:50:30 +1000</pubDate><guid>http://kaistriega.com/blog/mechanical-sympathy/array-of-structs-vs-struct-of-arrays/</guid><description>&lt;p&gt;I&amp;rsquo;ve been putting together a talk about &lt;a href="https://github.com/Kai-Striega/speeches/tree/main/things-I-dont-worry-about-as-NumPy-does-them-for-me"&gt;the things I don&amp;rsquo;t worry about, because NumPy does them for me&lt;/a&gt;:
the performance patterns I kept running into over seven years of reviewing NumPy code written by people far
smarter than me. What an array actually is. When &lt;code&gt;reshape&lt;/code&gt; quietly copies six gigabytes. What broadcasting
promises not to allocate. I did a practice run of it at &lt;a href="https://python.sydney/"&gt;SydPy&lt;/a&gt; recently.&lt;/p&gt;
&lt;p&gt;The NumPy-specific parts landed fine. Then I got to a slide which says that a copy isn&amp;rsquo;t slow because the CPU
is busy, it&amp;rsquo;s slow because the bytes have to physically &lt;em&gt;move&lt;/em&gt;; that main memory will only hand them over at
something like 20 GB/s; and that while that&amp;rsquo;s happening your cache is filling up with data you will never look
at again.&lt;/p&gt;</description></item></channel></rss>