<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>Erik Reed</title>
    <subtitle>In which I ramble about things probably related to software. But maybe not, eh? No, I do.</subtitle>
    <link rel="self" type="application/atom+xml" href="https://99a75f26.erikriffs.pages.dev/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://99a75f26.erikriffs.pages.dev"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2026-08-07T04:22:39+00:00</updated>
    <id>https://99a75f26.erikriffs.pages.dev/atom.xml</id>
    <entry xml:lang="en">
        <title>Antisocial coding</title>
        <published>2026-08-07T04:22:39+00:00</published>
        <updated>2026-08-07T04:22:39+00:00</updated>
        
        <author>
          <name>erik</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://99a75f26.erikriffs.pages.dev/antisocial-coding/"/>
        <id>https://99a75f26.erikriffs.pages.dev/antisocial-coding/</id>
        
        <content type="html" xml:base="https://99a75f26.erikriffs.pages.dev/antisocial-coding/">&lt;p&gt;I would have appreciated the human connection more had I known what would come. I miss being able to scroll through online content and knowing it was &lt;em&gt;probably&lt;/em&gt; written by a human being. If not, it was obviously not. Music, video, and photos were likely real. Nice looking websites were meticulously crafted or plagiarized. Stack overflow and github were vibrant. People spent time on what they wrote and published.&lt;/p&gt;
&lt;p&gt;Coding now is antisocial. There is no need to open a PR, post issues, comment on stackoverflow. It will be lost in the agentic ocean. There&#39;s no need to talk to anyone aside from your favorite model. Or reason to share, really. What you built and want to share is now built daily: it&#39;s easier and more fun to do it &quot;yourself&quot;.&lt;/p&gt;
&lt;p&gt;Open source as we knew it is over. The internet is as busy as ever yet it feels so stagnant. The zero barrier of entry makes everything look the same. There is little reason now to hone your craft.&lt;/p&gt;
&lt;p&gt;Truly remarkable things are being built without the slightest bit of understanding by a human being, all while being done without any human interaction. If we&#39;re lucky, someone will use them. Soon we&#39;ll be lucky to even be aware of the things being built.&lt;/p&gt;
&lt;p&gt;Not a singularity, no. Just noise pollution and consequent end of the internet being a source of human interaction.&lt;/p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Algorithmic Trip Planning (Part 2)</title>
        <published>2015-03-23T05:34:00+00:00</published>
        <updated>2015-03-23T05:34:00+00:00</updated>
        
        <author>
          <name>erik</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://99a75f26.erikriffs.pages.dev/algorithmic-trip-planning-part-2/"/>
        <id>https://99a75f26.erikriffs.pages.dev/algorithmic-trip-planning-part-2/</id>
        
        <content type="html" xml:base="https://99a75f26.erikriffs.pages.dev/algorithmic-trip-planning-part-2/">&lt;p&gt;My next trip is an adventure to the Middle East, prompted by a fare drop by Turkish Airlines. San Francisco to Istanbul via Turkish is a new route and fares were quite good relative to historical data (along with other critera), prompting a &lt;a rel=&quot;external&quot; href=&quot;http://adioso.com/deals&quot;&gt;nifty algorithm&lt;/a&gt; to send me an email. Seeing $680 round-trip, I naturally bought the ticket.&lt;/p&gt;
&lt;p&gt;Primarily three modifications of my &lt;a href=&quot;https://99a75f26.erikriffs.pages.dev/algorithmic-trip-planning/&quot;&gt;previous algorithm&lt;/a&gt; allow for novelty:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Searching round trip fares when they are cheaper than one way; that is, introducing a round-trip fare when a route of one ways has a complementary OD pair (e.g. &lt;em&gt;SFO -&amp;gt; HRG -&amp;gt; [intermediate cities] -&amp;gt; HRG -&amp;gt; SFO&lt;/em&gt; has a complementary/reversed OD pair)&lt;/li&gt;
&lt;li&gt;Leveraging intermediate city fares, omitting the remainder of an itinerary (e.g. buying a ticket from Egypt to Hungary, but getting off at a layover in Turkey&lt;/li&gt;
&lt;li&gt;Airport proximity: allowing different airport codes per city hop (e.g. flying into Cyprus&#39; ECN, out of LCA, which is 45km away)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It turns out, including the above does not significantly increase the search space, which is a nice way to say, a linear penalty is miniscule if we&#39;re already at &lt;em&gt;O(n!)&lt;/em&gt;, where &lt;em&gt;n&lt;/em&gt; is the number of airport codes. Consequently, with naive brute force enumeration, I find runtime to be sub-20 seconds via Pypy.&lt;/p&gt;
&lt;p&gt;The full route is as follows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;San Francisco (SFO) -&amp;gt; Istanbul (IST) -&amp;gt; Hurghada (HRG) $680 — get off at IST&lt;/li&gt;
&lt;li&gt;Istanbul (IST) -&amp;gt; Cyprus (ECN) $108&lt;/li&gt;
&lt;li&gt;Cyprus (LCA) -&amp;gt; Tel Aviv (TLV) $76&lt;/li&gt;
&lt;li&gt;Tel Aviv (TLV) -&amp;gt; Amman (AMM) — unknown: bus fare&lt;/li&gt;
&lt;li&gt;Amman (AMM) -&amp;gt; Cairo (CAI) $184&lt;/li&gt;
&lt;li&gt;Cairo (CAI) -&amp;gt; Hurghada (HRG) $103&lt;/li&gt;
&lt;li&gt;Hurghada (HRG) -&amp;gt; San Francisco (SFO) — return flight&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Total: $1150&lt;/strong&gt; (plus bus fare from Jerusalem to Amman).&lt;/p&gt;
&lt;figure class=&quot;maps&quot;&gt;
  &lt;img src=&quot;/assets/route-middle-east-world.svg&quot; alt=&quot;World map of the route, starting and ending in San Francisco.&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot;&gt;
  &lt;img src=&quot;/assets/route-middle-east-region.svg&quot; alt=&quot;Regional map of the Middle East legs: Istanbul, Cyprus, Tel Aviv, Amman, Cairo and Hurghada.&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot;&gt;
&lt;/figure&gt;
&lt;p&gt;I also had a few goals/constraints, which all were satisified:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;No propeller aircraft — in this case, all A320s&lt;/li&gt;
&lt;li&gt;Direct flights only&lt;/li&gt;
&lt;li&gt;Reasonable departure times — i.e. no waking up early or arriving after 8pm&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Definitely lots of opportunity for improvement computation/algorithm-wise — perhaps another trip will yield some insight.&lt;/p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Python constants to arguments</title>
        <published>2015-02-25T21:53:00+00:00</published>
        <updated>2015-02-25T21:53:00+00:00</updated>
        
        <author>
          <name>erik</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://99a75f26.erikriffs.pages.dev/python-constants-to-arguments/"/>
        <id>https://99a75f26.erikriffs.pages.dev/python-constants-to-arguments/</id>
        
        <content type="html" xml:base="https://99a75f26.erikriffs.pages.dev/python-constants-to-arguments/">&lt;p&gt;A quick snippet to convert any primitive type constant in a Python main module to program arguments. E.g., if I have main.py with&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-8&quot;&gt;FEATURE_SELECTION&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; True&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-8&quot;&gt;NUMBER_OF_ROWS&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; 100&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt; main&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt;  #&lt;/span&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt; rest of program&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and I want to trivially and automatically parse command line arguments to replace the constants, which is really a bad idea for a variety of reasons, an automatic argparser can generate this:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ python main.py --help&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;usage: main.py [-h] [--number-of-rows NUMBER_OF_ROWS]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;               [--feature-selection FEATURE_SELECTION]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;optional arguments:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -h, --help            show this help message and exit&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  --number-of-rows NUMBER_OF_ROWS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        Auto-generated constant (int). (default: 100)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  --feature-selection FEATURE_SELECTION&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        Auto-generated constant (bool). (default: True)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The following snippet can be appended to a main module to hackily replace the constants!&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;import&lt;/span&gt;&lt;span&gt; argparse&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;parser&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; =&lt;/span&gt;&lt;span&gt; argparse&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-3&quot;&gt;ArgumentParser&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-9 z-d-i&quot;&gt; formatter_class&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt;=&lt;/span&gt;&lt;span&gt;argparse&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;ArgumentDefaultsHelpFormatter&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt; update global constants with args&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt;map&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;lambda&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8 z-d-i&quot;&gt; kv&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt; parser&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-3&quot;&gt;add_argument&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; %&lt;/span&gt;&lt;span&gt; kv&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;0&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-3&quot;&gt;lower&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-3&quot;&gt;replace&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-9 z-d-i&quot;&gt; default&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt;=&lt;/span&gt;&lt;span&gt;kv&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-9 z-d-i&quot;&gt; type&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt;type&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;kv&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt; if&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt; type&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;kv&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; !=&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt; bool&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt; else&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt; str&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-9 z-d-i&quot;&gt;                                   help&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;Auto-generated constant (&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; %&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt; type&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;kv&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-11 z-d-9&quot;&gt;__name__&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-9 z-d-i&quot;&gt; dest&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt;=&lt;/span&gt;&lt;span&gt;kv&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;0&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt;    filter&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;lambda&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8 z-d-i&quot;&gt; kv&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt; kv&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;0&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; ==&lt;/span&gt;&lt;span&gt; kv&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;0&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-3&quot;&gt;upper&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt; and&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt; type&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;kv&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt; in&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt;int&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt; bool&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt; globals&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-3&quot;&gt;iteritems&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;args&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; =&lt;/span&gt;&lt;span&gt; parser&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-3&quot;&gt;parse_args&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt;globals&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-3&quot;&gt;update&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;k&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt; eval&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;v&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt; if&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt; type&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;v&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; ==&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt; str&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt; else&lt;/span&gt;&lt;span&gt; v&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt; for&lt;/span&gt;&lt;span&gt; k&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; v&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt; in&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt; vars&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;args&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-3&quot;&gt;iteritems&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt; if&lt;/span&gt;&lt;span&gt; k&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; ==&lt;/span&gt;&lt;span&gt; k&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-3&quot;&gt;upper&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And now, I can do:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ python main.py --number-of-rows=10&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;without ever having to add logic specific to constants; I can just add constants and the flags are auto-generated.&lt;/p&gt;
&lt;p&gt;Just be wary this is incredibly bad practice due to monkey patching and insecure due to the use of eval(). However for quick scripts, I find it to be effective.&lt;/p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Algorithmic trip planning</title>
        <published>2014-08-09T05:44:00+00:00</published>
        <updated>2014-08-09T05:44:00+00:00</updated>
        
        <author>
          <name>erik</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://99a75f26.erikriffs.pages.dev/algorithmic-trip-planning/"/>
        <id>https://99a75f26.erikriffs.pages.dev/algorithmic-trip-planning/</id>
        
        <content type="html" xml:base="https://99a75f26.erikriffs.pages.dev/algorithmic-trip-planning/">&lt;p&gt;I write this in Singapore, city number three in a ten city voyage obtained via brute force enumeration of route permutations for a set of cities I desired to visit in Southeast Asia. I ended up purchasing 11 one-way tickets, starting and ending in San Francisco. Here I&#39;ll describe my route and give a high level algorithm.&lt;/p&gt;
&lt;p&gt;My route, which I generated algorithmically, is the following:&lt;/p&gt;
&lt;p&gt;Depart from San Francisco, United States [Jul 30] (via Philippine Airlines)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Tokyo, Japan for 1 night (layover) [Aug 01] (via Jetstar Asia)&lt;/li&gt;
&lt;li&gt;Manila, Philippines for 5 nights [Aug 05] (via Jetstar Asia)&lt;/li&gt;
&lt;li&gt;Singapore, Singapore for 7 nights [Aug 13] (via Jetstar Asia)&lt;/li&gt;
&lt;li&gt;Ho Chi Minh City, Vietnam for 4 nights [Aug 17] (via AirAsia)&lt;/li&gt;
&lt;li&gt;Bangkok, Thailand for 4 nights [Aug 21] (via AirAsia)&lt;/li&gt;
&lt;li&gt;Phuket, Thailand for 4 nights [Aug 26] (via AirAsia)&lt;/li&gt;
&lt;li&gt;Kuala Lumpur, Malaysia for 3 nights [Aug 30] (via AirAsia)&lt;/li&gt;
&lt;li&gt;Phnom Penh, Cambodia for 4 nights [Sep 03] (via AirAsia)&lt;/li&gt;
&lt;li&gt;Jakarta, Indonesia for 5 nights [Sep 08] (via AirAsia)&lt;/li&gt;
&lt;li&gt;Bali, Indonesia for 5 nights [Sep 14] (via Garuda Indonesia)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Arrive at San Francisco, United States [Sep 14]&lt;/p&gt;
&lt;figure class=&quot;maps&quot;&gt;
  &lt;img src=&quot;/assets/route-southeast-asia-world.svg&quot; alt=&quot;World map of the eleven-leg route, starting and ending in San Francisco.&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot;&gt;
  &lt;img src=&quot;/assets/route-southeast-asia-region.svg&quot; alt=&quot;Regional map of the Southeast Asia legs, from Tokyo down through Manila, Singapore, Ho Chi Minh City, Bangkok, Phuket, Kuala Lumpur, Phnom Penh, Jakarta and Bali.&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot;&gt;
&lt;/figure&gt;
&lt;p&gt;The total cost of airfare was &lt;strong&gt;$1670 USD&lt;/strong&gt;, a good majority of the cost coming from the two tickets out/into SFO (San Francisco). It is worth noting this cost isn&#39;t particularly optimal as the tickets were purchased only 6 weeks in advice, and fare prices during July/August tend to skyrocket.&lt;/p&gt;
&lt;p&gt;Consider the traveling salesman problem (TSP) for this scenario: given &lt;em&gt;N=10&lt;/em&gt; cities, find the optimal route that reaches all cities (without revisiting) which minimizes some cost function. In this case, the TSP search space can be amended to include a few more dimensions that influence cost. Most importantly, these dimensions are outbound date and time until departure (i.e. days in advance a ticket is purchased), as prices heavily fluctuate based on these factors. Using historical data, one can build a model and predict the fare prices as well as time to buy, however that&#39;s not the focus here (although worth a separate discussion). Quite simply, pick your favorite regression to do this. Additionally I imposed a days-per-city constraint: I wanted to spend between &lt;em&gt;a=4&lt;/em&gt; and &lt;em&gt;b=8&lt;/em&gt; days per city, so this was included as a per-city dimension.&lt;/p&gt;
&lt;p&gt;I implemented the above in Python using historical data of &lt;a rel=&quot;external&quot; href=&quot;http://adioso.com&quot;&gt;Adioso&lt;/a&gt;, whom have the best fare coverage over Southeast Asia–although as a data scientist at Adioso, I am biased. I generated a couple dozen candidate routes and programmatically validated the fares (prioritizing direct flights), and purchased the &quot;best&quot; route by hand.&lt;/p&gt;
&lt;p&gt;Once my trip is farther along or complete, I&#39;ll point out some pros and cons of this approach and describe two philosophies I have used for traveling: stochastic local search and global optimization (a la the traveling salesman problem).&lt;/p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Foo/bar decreases readability</title>
        <published>2014-06-29T23:12:00+00:00</published>
        <updated>2014-06-29T23:12:00+00:00</updated>
        
        <author>
          <name>erik</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://99a75f26.erikriffs.pages.dev/foobar-decreases-readability/"/>
        <id>https://99a75f26.erikriffs.pages.dev/foobar-decreases-readability/</id>
        
        <content type="html" xml:base="https://99a75f26.erikriffs.pages.dev/foobar-decreases-readability/">&lt;p&gt;I think using &lt;em&gt;foo&lt;/em&gt; or &lt;em&gt;bar&lt;/em&gt; in code snippets is detrimental when visually parsing the code–especially when the syntax is unfamiliar. For example, I was browsing through some php code samples to find this:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;php&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;foreach&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-11 z-d-9&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;z-l-11 z-d-9&quot;&gt;bar&lt;/span&gt;&lt;span&gt; as&lt;/span&gt;&lt;span class=&quot;z-l-11 z-d-9&quot;&gt; $&lt;/span&gt;&lt;span class=&quot;z-l-11 z-d-9&quot;&gt;foo&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt;    //&lt;/span&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt; do some stuff with $foo&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Great. Now, say I don&#39;t know php; is foo an element or the array? From the comment, it&#39;s the array. Then I alt-tab, scroll through some code, and immediately lose 80% of what I gleaned from the context switch, only recalling &quot;bar as foo&quot;. That means absolutely nothing. But if the snippet avoided the non-informative foobar usage, it would be so much more intuitive.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;php&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;foreach&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-11 z-d-9&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;z-l-11 z-d-9&quot;&gt;files&lt;/span&gt;&lt;span&gt; as&lt;/span&gt;&lt;span class=&quot;z-l-11 z-d-9&quot;&gt; $&lt;/span&gt;&lt;span class=&quot;z-l-11 z-d-9&quot;&gt;file&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt;    //&lt;/span&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt; do some stuff with $file&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Files as file… I&#39;ll remember that easier than &quot;foo as bar&quot;. Using some simple, practical variable names makes example code more clear. Applying this to a function:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt; foo&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;z-d-9 z-d-i&quot;&gt; bar1&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt; int&lt;/span&gt;&lt;span class=&quot;z-d-9 z-d-i&quot;&gt; bar2&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;versus&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt; func&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;z-d-9 z-d-i&quot;&gt; arg1&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt; int&lt;/span&gt;&lt;span class=&quot;z-d-9 z-d-i&quot;&gt; arg2&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Another foo-embedded code snippet:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt;xargs&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;ifoo&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; sh&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;tar zxvf foo.tar.gz &amp;amp;&amp;amp; mv $(echo foo | sed s/-.*$//) foo&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now why not have &quot;file&quot; instead of &quot;foo&quot;? It probably would make more sense.&lt;/p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>MATLAB image rotate without black bars</title>
        <published>2014-04-06T15:32:00+00:00</published>
        <updated>2014-04-06T15:32:00+00:00</updated>
        
        <author>
          <name>erik</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://99a75f26.erikriffs.pages.dev/matlab-image-rotate-without-black-bars/"/>
        <id>https://99a75f26.erikriffs.pages.dev/matlab-image-rotate-without-black-bars/</id>
        
        <content type="html" xml:base="https://99a75f26.erikriffs.pages.dev/matlab-image-rotate-without-black-bars/">&lt;p&gt;MATLAB fills the empty region of rotated images with solid black (i.e. zero padding). This is rather problematic for various computer vision algorithms (e.g. fusion, registration, similarity). Unfortunately, this is not a parameter in the imrotate command. The following addresses this issue.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;matlab&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;img = imread&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;cameraman.tif&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;rotated = imrotate&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;img, &lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;45&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;bicubic&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;crop_upper = max&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;find&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;diag&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;rotated&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; ~=&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; 0&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;crop_lower = min&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;find&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;diag&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;rotated&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; ~=&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; 0&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;crop_diff = crop_upper-crop_lower;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;rotated2 = imcrop&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;rotated, &lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span&gt;crop_lower, crop_lower, crop_diff, crop_diff&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt; visualize&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;subplot&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;3&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;imshow&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;img&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;subplot&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;3&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;2&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;imshow&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;rotated&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;subplot&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;3&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;3&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;imshow&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;rotated2&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href=&quot;/assets/mat_rotate.png&quot;&gt;&lt;img src=&quot;/assets/mat_rotate-1024x366.png&quot; alt=&quot;Original cameraman image, the same image rotated 45 degrees with black corner padding, and the cropped result with no black bars&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This is similar to &lt;a rel=&quot;external&quot; title=&quot;roirotate&quot; href=&quot;https://www.mathworks.com/matlabcentral/fileexchange/1825-fill-corners-of-rotated-image&quot;&gt;roirotate&lt;/a&gt;, but without explicitly declaring a region of interest or dealing the possibility of &lt;em&gt;any&lt;/em&gt; zero-padding (black bar).&lt;/p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Miscellaneous useful Bash/shell commands</title>
        <published>2014-01-19T02:27:00+00:00</published>
        <updated>2014-01-19T02:27:00+00:00</updated>
        
        <author>
          <name>erik</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://99a75f26.erikriffs.pages.dev/miscellaneous-useful-bashshell-commands/"/>
        <id>https://99a75f26.erikriffs.pages.dev/miscellaneous-useful-bashshell-commands/</id>
        
        <content type="html" xml:base="https://99a75f26.erikriffs.pages.dev/miscellaneous-useful-bashshell-commands/">&lt;p&gt;I&#39;ve been cataloging various shell commands and scripts that have been quite useful for various Linux (and even Windows via cygwin/git-shell) activities. The ones I list here are either not found via Google search or required a bit of hackery to suit my purposes.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Add a copyright (or author) comment to a bunch of Java files.&lt;/strong&gt;&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; src&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; f&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;exec&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; sh&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;sed -i &amp;#39;1s/^/\/\/ Copyright 2013 Erik Reed (erik@somewhere.com)\n\n/&amp;#39; {}&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt; \;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Result:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;java&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt;//&lt;/span&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt; Copyright 2013 Erik Reed (erik@somewhere.com)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;package&lt;/span&gt;&lt;span class=&quot;z-d-7&quot;&gt; java&lt;/span&gt;&lt;span class=&quot;z-d-7&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-7&quot;&gt;com&lt;/span&gt;&lt;span class=&quot;z-d-7&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-7&quot;&gt;tons&lt;/span&gt;&lt;span class=&quot;z-d-7&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-7&quot;&gt;of&lt;/span&gt;&lt;span class=&quot;z-d-7&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-7&quot;&gt;nested&lt;/span&gt;&lt;span class=&quot;z-d-7&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-7&quot;&gt;packages&lt;/span&gt;&lt;span class=&quot;z-d-7&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-4 z-l-bg2 z-d-12&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;z-d-7&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-7&quot;&gt;no&lt;/span&gt;&lt;span class=&quot;z-d-7&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-7&quot;&gt;reason&lt;/span&gt;&lt;span class=&quot;z-d-7&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-7&quot;&gt;coolapp&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-10&quot;&gt; java&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-10&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-10&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-10&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-10&quot;&gt;Serializable&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-10&quot;&gt; java&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-10&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-10&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-10&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-10&quot;&gt;ParseException&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt;//&lt;/span&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt; ...&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Convert many image formats in parallel (jpegs to png here). Using 64 processes in this case:&lt;/strong&gt;&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; .&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; f&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;*.jpg&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;print0&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt; xargs&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;n1&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;P&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; 64&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; sh&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;convert &amp;quot;$1&amp;quot; &amp;quot;${1%.jpg}.png&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; sh&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Make file extensions lowercase (a common issue I&#39;ve had with mixing Windows/Linux).&lt;/strong&gt;&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; .&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;*.*&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;exec&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; sh&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;  a=$(echo {} | sed -r &amp;quot;s/([^.]*)\$/\L\1/&amp;quot;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;  [ &amp;quot;$a&amp;quot; != &amp;quot;{}&amp;quot; ] &amp;amp;&amp;amp; mv &amp;quot;{}&amp;quot; &amp;quot;$a&amp;quot; &lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt; \;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Rsync files to/from remote machine as root (e.g. to backup multiple users, root owned files, or a full disk backup).&lt;/strong&gt;&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt;rsync&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;avze&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; ssh&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;-rsync-path=&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;sudo rsync&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; myUser@REMOTE_SERVER:/REMOTE_PATH/&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; LOCAL_PATH&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Clear disk cache and swap:&lt;/strong&gt;&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt; clear cache&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt;sync&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt; echo&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; 3&lt;/span&gt;&lt;span&gt; &amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; /proc/sys/vm/drop_caches&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt; clear swap&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt;swapoff&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;a&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt; swapon&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;a&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Print the mean and standard deviation of a file/stdin (in one line):&lt;/strong&gt;&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt;awk&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;{ sum += $1; sumsq += $1*$1 } END { printf &amp;quot;Mean: %f, Std: %f\n&amp;quot;, sum/NR, sqrt(sumsq/NR - (sum/NR)^2) }&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;</content>
        
    </entry>
    <entry xml:lang="en">
        <title>NTFS compression is terrible for many small files</title>
        <published>2013-02-24T10:15:00+00:00</published>
        <updated>2013-02-24T10:15:00+00:00</updated>
        
        <author>
          <name>erik</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://99a75f26.erikriffs.pages.dev/ntfs-compression-is-terrible-for-many-small-files/"/>
        <id>https://99a75f26.erikriffs.pages.dev/ntfs-compression-is-terrible-for-many-small-files/</id>
        
        <content type="html" xml:base="https://99a75f26.erikriffs.pages.dev/ntfs-compression-is-terrible-for-many-small-files/">&lt;p&gt;Don&#39;t use NTFS compression for many small files.&lt;/p&gt;
&lt;p&gt;I recently tried to enable NTFS compression on some log files to see how the compression ratio would fare versus batch compressing them all. I experimented with a 64MB folder with ~10k files and noticed a &lt;strong&gt;1.4GB increase&lt;/strong&gt; in disk usage. Interesting… let&#39;s take a look.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Pre-compression:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;/assets/ntfs-comp-1.png&quot;&gt;&lt;img src=&quot;/assets/ntfs-comp-1.png&quot; alt=&quot;Directory listing before compression: 64MB across roughly 10,000 files&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Folder properties:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;/assets/ntfs-comp-2.png&quot;&gt;&lt;img src=&quot;/assets/ntfs-comp-2.png&quot; alt=&quot;Folder properties dialog before compression&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Applying compression attribute:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;/assets/ntfs-comp-3.png&quot;&gt;&lt;img src=&quot;/assets/ntfs-comp-3-300x262.png&quot; alt=&quot;Windows dialog applying the compression attribute to the folder&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Post-compression:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;/assets/ntfs-comp-5.png&quot;&gt;&lt;img src=&quot;/assets/ntfs-comp-5.png&quot; alt=&quot;Folder properties after compression, showing 45MB&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Nice, a 30% compression ratio (64MB to 45MB). Considering that each file is typically 1-4KB, I thought this was reasonable (compared to the batch compression ratio of 10:1). But, I noticed an odd increase in disk usage:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;/assets/ntfs-comp-4.png&quot;&gt;&lt;img src=&quot;/assets/ntfs-comp-4.png&quot; alt=&quot;Drive properties showing free space fall from 2.6GB to 1.2GB&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;2.6GB down to 1.2GB. The only action taken was enabling NTFS compression on the above folder. Removing the compression attribute restores the lost 1.4GB of disk space.&lt;/p&gt;
&lt;p&gt;This is surprising for two reasons: NTFS compression is supposed to be beneficial for small files (4-64KB) &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-1-1&quot;&gt;&lt;a href=&quot;#fn-1&quot;&gt;[1]&lt;/a&gt;&lt;/sup&gt;, and the folder properties don&#39;t alert the user to any extreme loss of disk space.&lt;/p&gt;
&lt;section class=&quot;footnotes&quot;&gt;
&lt;ol class=&quot;footnotes-list&quot;&gt;
&lt;li id=&quot;fn-1&quot;&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;http://en.wikipedia.org/wiki/NTFS#File_compression&quot;&gt;http://en.wikipedia.org/wiki/NTFS#File_compression&lt;/a&gt; &lt;a href=&quot;#fr-1-1&quot;&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Batch emailing a CSV file of data using Python and SMTP</title>
        <published>2012-12-13T20:37:00+00:00</published>
        <updated>2012-12-13T20:37:00+00:00</updated>
        
        <author>
          <name>erik</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://99a75f26.erikriffs.pages.dev/batch-emailing-a-csv-file-of-data-using-python-and-smtp/"/>
        <id>https://99a75f26.erikriffs.pages.dev/batch-emailing-a-csv-file-of-data-using-python-and-smtp/</id>
        
        <content type="html" xml:base="https://99a75f26.erikriffs.pages.dev/batch-emailing-a-csv-file-of-data-using-python-and-smtp/">&lt;p&gt;A quick script for sending a batch of emails using a csv file. Each csv line contains an email address and the information I wish to populate in the email content and send to a single recipient. In this case, I wanted to send grades out for a group of students using a spreadsheet of grades from Google docs (and with my Gmail). With cursory preprocessing, I put the data in this format:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Firstname1 Lastname1,userID1,91.7,0.979&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Firstname2 Lastname2,userID2,60.8,0.061&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;...&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then, we can parse it and fire off our mailer with the following:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt; erik reed&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;import&lt;/span&gt;&lt;span&gt; smtplib&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;import&lt;/span&gt;&lt;span&gt; csv&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;from&lt;/span&gt;&lt;span&gt; time&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt; import&lt;/span&gt;&lt;span&gt; sleep&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;from&lt;/span&gt;&lt;span&gt; email&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;mime&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;text&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt; import&lt;/span&gt;&lt;span&gt; MIMEText&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-8&quot;&gt;FROM_ADDRESS&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;ADD_ME@asd.com&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-8&quot;&gt;SMTP_SERVER&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;smtp.gmail.com:587&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-8&quot;&gt;SMTP_USER&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;ADD_ME&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-8&quot;&gt;SMTP_PASS&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;ADD_ME&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt; mail&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8 z-d-i&quot;&gt;msg&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  server&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; =&lt;/span&gt;&lt;span&gt; smtplib&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-3&quot;&gt;SMTP&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-8&quot;&gt;SMTP_SERVER&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  server&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-3&quot;&gt;starttls&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  server&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-3&quot;&gt;login&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-8&quot;&gt;SMTP_USER&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-d-8&quot;&gt;SMTP_PASS&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  server&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-3&quot;&gt;sendmail&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-d-8&quot;&gt;FROM_ADDRESS&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; msg&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;To&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; msg&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-3&quot;&gt;as_string&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  server&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-3&quot;&gt;quit&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;f&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt; open&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;grades.csv&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;reader&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; =&lt;/span&gt;&lt;span&gt; csv&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-3&quot;&gt;reader&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;f&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;for&lt;/span&gt;&lt;span&gt; row&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt; in&lt;/span&gt;&lt;span&gt; reader&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  content&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;Hi &lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; +&lt;/span&gt;&lt;span&gt; row&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;0&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-3&quot;&gt;strip&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-3&quot;&gt;split&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;0&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  content&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; +=&lt;/span&gt;&lt;span&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&amp;#39;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;This is an automated message with your final exam grade. If&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;you have any questions regarding exam grade, see ***** if you&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;are in SV, otherwise talk to me. The average grade on the final&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;exam was 76% with a standard deviation of 12.5%.&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&amp;#39;&amp;#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  content&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; +=&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;You received a &lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; +&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt; str&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;row&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;2&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; +&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;%, corresponding to &lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  content&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; +=&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;the &lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; +&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt; str&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt;float&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;row&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;3&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; 100&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; +&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;th percentile.&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  content&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; +=&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;Erik&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  msg&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-d-3&quot;&gt; MIMEText&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;content&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  msg&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;To&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; =&lt;/span&gt;&lt;span&gt; row&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; +&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;@cmu.edu&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  msg&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;From&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-d-8&quot;&gt; FROM_ADDRESS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  msg&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;Subject&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;Fastcode: exam grade for &lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-d-1&quot;&gt; +&lt;/span&gt;&lt;span&gt; row&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  msg&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-3&quot;&gt;add_header&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;reply-to&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-d-8&quot;&gt; FROM_ADDRESS&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt;  print&lt;/span&gt;&lt;span&gt; msg&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-3&quot;&gt;as_string&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-3&quot;&gt;  mail&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;msg&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-d-3&quot;&gt;  sleep&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt; #&lt;/span&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt; pause after each email send&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;f&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span class=&quot;z-d-3&quot;&gt;close&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This could be cleaned up a bit using better Python syntax, but it does the trick. Each email will look something like the following:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Hi Firstname1,&lt;/p&gt;
&lt;p&gt;This is an automated message with your final exam grade. If&lt;br /&gt;
you have any questions regarding exam grade, see ***** if you&lt;br /&gt;
are in SV, otherwise talk to me. The average grade on the final&lt;br /&gt;
exam was 76% with a standard deviation of 12.5%.&lt;/p&gt;
&lt;p&gt;You received a 45%, corresponding to the 2.0th percentile.&lt;/p&gt;
&lt;p&gt;Erik&lt;/p&gt;
&lt;/blockquote&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Web server cache warming by crawling sitemaps</title>
        <published>2012-04-02T14:56:00+00:00</published>
        <updated>2012-04-02T14:56:00+00:00</updated>
        
        <author>
          <name>erik</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://99a75f26.erikriffs.pages.dev/web-server-cache-warming-by-crawling-sitemaps/"/>
        <id>https://99a75f26.erikriffs.pages.dev/web-server-cache-warming-by-crawling-sitemaps/</id>
        
        <content type="html" xml:base="https://99a75f26.erikriffs.pages.dev/web-server-cache-warming-by-crawling-sitemaps/">&lt;p&gt;&lt;strong&gt;Background&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Hosting a website on a home server, especially one with low traffic, can result in long response times when retrieving pages. Intuitively, it seems like high traffic should slow the response of a server, and that a server with no CPU load should be able to return web pages faster. But–high traffic servers have a cache advantage. When a user visits a page that has already been recently served, that page is fresh in memory. This is a definite bonus from having the web server retrieve the page from a hard drive, which can take many orders of magnitude longer in IO time &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-1-1&quot;&gt;&lt;a href=&quot;#fn-1&quot;&gt;[1]&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;
&lt;p&gt;The low traffic home server is at a disadvantage because it is serving little content. The CPU is mostly idle and pages aren&#39;t being frequently accessed, decreasing the probability that a page will already be in memory when a user requests it. This results in cache misses, forcing data to be retrieved from disk. It is also said that the cache is &quot;cold&quot;. As an example of how bad this can be, this site takes 1-2 seconds longer to load after a recent reboot, forcing all web data to be accessed from disk.&lt;/p&gt;
&lt;p&gt;There are many solutions to this. Notable methods are: the entire web directory could be allocated to ramdisk &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-2-1&quot;&gt;&lt;a href=&quot;#fn-2&quot;&gt;[2]&lt;/a&gt;&lt;/sup&gt;; implement mem-caching in apache &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-3-1&quot;&gt;&lt;a href=&quot;#fn-3&quot;&gt;[3]&lt;/a&gt;&lt;/sup&gt;; object code (or opcode) caching for server-side languages like PHP &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-4-1&quot;&gt;&lt;a href=&quot;#fn-4&quot;&gt;[4]&lt;/a&gt;&lt;/sup&gt;; and setting expiration dates (expire headers) to allow caching on the client&#39;s browser &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-5-1&quot;&gt;&lt;a href=&quot;#fn-5&quot;&gt;[5]&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;
&lt;p&gt;I use opcode caching and expire headers to speed page load time, which are very easy to implement. But these don&#39;t ensure web data is in memory. Or at least, ensure that there is a decent probability pages are in memory. For my ancient server, retrieving data from disk is the most time consuming factor of page load. Further, I don&#39;t want caching to require memory like a process; the operating system&#39;s disk cache can be leveraged to provide a cache that is optional. That is, if I&#39;m running a bunch of memory intensive code in the background, the operating system will automatically prioritize it instead of keeping web data in memory, since the cached data is regarded as free. This is demonstrated below by the command &lt;code&gt;vmstat -m&lt;/code&gt;, where the cache column indicates that 101 MB of disk is in memory, but classifies as free memory (see &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-6-1&quot;&gt;&lt;a href=&quot;#fn-6&quot;&gt;[6]&lt;/a&gt;&lt;/sup&gt;).&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 0  0     43    573    141    101    0    0     5    20   25   18  1  1 90  7&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;One way to leverage the operating system cache as described above is to crawl the website. Crawling the site forces the server to load all resources from the disk. If there is sufficient free RAM and the site is small, like most blogs, the entirety of the web data will sit in the operating system cache. In the domain of serving web content, this can be called cache warming, which is analogous to user-guided anticipatory paging &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-7-1&quot;&gt;&lt;a href=&quot;#fn-7&quot;&gt;[7]&lt;/a&gt;&lt;/sup&gt; or pre-fetching.&lt;/p&gt;
&lt;p&gt;Crawling a site is easy if you have a sitemap. Several programs can automatically generate them, including sitemaps specific to blogs like WordPress &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-8-1&quot;&gt;&lt;a href=&quot;#fn-8&quot;&gt;[8]&lt;/a&gt;&lt;/sup&gt;. Mine is &lt;a rel=&quot;external&quot; href=&quot;http://erikriffs.com/sitemap.xml&quot;&gt;here&lt;/a&gt;, where the XML content is visible when viewing the source. Since sitemaps have a standardized format, the following commands can be used to grab the URL of every page to crawl:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt;wget&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;O&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; erikriffs.com/sitemap.xml&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt; grep&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;E&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;o&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;lt;loc&amp;gt;.*&amp;lt;/loc&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt; sed&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;s/&amp;lt;loc&amp;gt;//g&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;s/&amp;lt;\/loc&amp;gt;//g&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Output:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;erik@erik-server ~ $ wget -O - erikriffs.com/sitemap.xml | grep -E -o &amp;#39;&amp;lt;loc&amp;gt;.*&amp;lt;/loc&amp;gt;&amp;#39; | sed -e &amp;#39;s/&amp;lt;loc&amp;gt;//g&amp;#39; -e &amp;#39;s/&amp;lt;\/loc&amp;gt;//g&amp;#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;--2012-04-02 14:29:38--  http://erikriffs.com/sitemap.xml&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Resolving erikriffs.com... 98.234.52.166&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Connecting to erikriffs.com|98.234.52.166|:80... connected.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;HTTP request sent, awaiting response... 200 OK&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Length: 1641 (1.6K) [application/xml]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Saving to: `STDOUT&amp;#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;100%[=======================================&amp;gt;] 1,641       --.-K/s   in 0s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;2012-04-02 14:29:39 (93.0 MB/s) - written to stdout [1641/1641]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;http://erikriffs.com/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;http://erikriffs.com/latex-ieee-bibliography-error/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;http://erikriffs.com/index/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;http://erikriffs.com/matlab-parfor-performance/&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Having obtained the list of URLs, this can be piped back into wget to download every page along with the resources required, like css, js, and images.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt;wget&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;O&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; erikriffs.com/sitemap.xml&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt; grep&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;E&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;o&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;lt;loc&amp;gt;.*&amp;lt;/loc&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt; sed&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;s/&amp;lt;loc&amp;gt;//g&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;s/&amp;lt;\/loc&amp;gt;//g&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt; wget&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;-delete-after&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The above one-liner keeps web data fresh in the cache. Temporarily. As other activity occurs on the operating system, the amount of site content in memory will slowly decrease. Using &lt;code&gt;crontab -e&lt;/code&gt; and the crawling one-liner allows for an hourly cache warming. It is also a far simpler alternative to &lt;a rel=&quot;external&quot; href=&quot;http://www.pixelenvision.com/1572/php-cache-warmer-preloader-for-w3-total-cache/&quot;&gt;a PHP program&lt;/a&gt;, and unlike &lt;a rel=&quot;external&quot; href=&quot;http://www.tutorialarena.com/blog/using-wget-xml-sitemap-spider-drupal-website.php&quot;&gt;this Drupal example&lt;/a&gt;, will crawl images and other dependent resources (the author is missing the -p flag in wget).&lt;/p&gt;
&lt;section class=&quot;footnotes&quot;&gt;
&lt;ol class=&quot;footnotes-list&quot;&gt;
&lt;li id=&quot;fn-1&quot;&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;http://en.wikipedia.org/wiki/Memory_hierarchy#Application_of_the_concept&quot;&gt;http://en.wikipedia.org/wiki/Memory_hierarchy#Application_of_the_concept&lt;/a&gt; &lt;a href=&quot;#fr-1-1&quot;&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&quot;fn-2&quot;&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;http://www.cyberciti.biz/faq/howto-create-linux-ram-disk-filesystem/&quot;&gt;http://www.cyberciti.biz/faq/howto-create-linux-ram-disk-filesystem/&lt;/a&gt; &lt;a href=&quot;#fr-2-1&quot;&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&quot;fn-3&quot;&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;http://httpd.apache.org/docs/2.2/caching.html&quot;&gt;http://httpd.apache.org/docs/2.2/caching.html&lt;/a&gt; &lt;a href=&quot;#fr-3-1&quot;&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&quot;fn-4&quot;&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;http://blog.digitalstruct.com/2008/02/27/php-performance-series-caching-techniques/&quot;&gt;http://blog.digitalstruct.com/2008/02/27/php-performance-series-caching-techniques/&lt;/a&gt; &lt;a href=&quot;#fr-4-1&quot;&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&quot;fn-5&quot;&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;http://httpd.apache.org/docs/2.2/mod/mod_expires.html&quot;&gt;http://httpd.apache.org/docs/2.2/mod/mod_expires.html&lt;/a&gt; &lt;a href=&quot;#fr-5-1&quot;&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&quot;fn-6&quot;&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;http://stackoverflow.com/questions/6345020/linux-memory-buffer-vs-cache&quot;&gt;http://stackoverflow.com/questions/6345020/linux-memory-buffer-vs-cache&lt;/a&gt; &lt;a href=&quot;#fr-6-1&quot;&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&quot;fn-7&quot;&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;http://en.wikipedia.org/wiki/Paging#Anticipatory_paging&quot;&gt;http://en.wikipedia.org/wiki/Paging#Anticipatory_paging&lt;/a&gt; &lt;a href=&quot;#fr-7-1&quot;&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&quot;fn-8&quot;&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;http://wordpress.org/extend/plugins/google-sitemap-generator/&quot;&gt;http://wordpress.org/extend/plugins/google-sitemap-generator/&lt;/a&gt; &lt;a href=&quot;#fr-8-1&quot;&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Latex IEEE bibliography error</title>
        <published>2012-03-31T18:34:00+00:00</published>
        <updated>2012-03-31T18:34:00+00:00</updated>
        
        <author>
          <name>erik</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://99a75f26.erikriffs.pages.dev/latex-ieee-bibliography-error/"/>
        <id>https://99a75f26.erikriffs.pages.dev/latex-ieee-bibliography-error/</id>
        
        <content type="html" xml:base="https://99a75f26.erikriffs.pages.dev/latex-ieee-bibliography-error/">&lt;p&gt;The IEEE Latex format is a nightmare to work with. Nothing new there. One problem I had was using the IEEE template with bibliography that had worked for other conference styles. Now all I get is a cryptic error:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Latex:&lt;/strong&gt;&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;tex&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt;bibliographystyle&lt;/span&gt;&lt;span&gt;{IEEEtran}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt; argument is your BibTeX string definitions and bibliography database(s)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt;bibliography&lt;/span&gt;&lt;span&gt;{IEEEabrv,isrcs12}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Console output:&lt;/strong&gt;&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;(&amp;quot;C:\Program Files (x86)\MiKTeX 2.9\tex\latex\sttools\stfloats.sty&amp;quot;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;(C:\Users\Erik\Desktop\phd_stuff\papers\isrcs12_controlling_bns\isrcs12.aux)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;(C:\Users\Erik\Desktop\phd_stuff\papers\isrcs12_controlling_bns\isrcs12.bbl&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;! LaTeX Error: Something&amp;#39;s wrong--perhaps a missing \item.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;See the LaTeX manual or LaTeX Companion for explanation.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Type  H   for immediate help.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;l.24 \end{thebibliography}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;?&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I couldn&#39;t find the solution on Google and spent excessive time trying to figure out the issue only to discover:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;bibtex&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;inproceedings&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-10&quot;&gt;khanautomated2011&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt;   title&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;span&gt;Automated Refinement of Bayes Networks&amp;#39; Parameters based on Test Ordering Constraints&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt;   author&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;span&gt;Khan, O.Z. and Poupart, P. and Agosta, J.M.&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   booktitle&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;span&gt;Twenty-Fifth Annual Conference on Neural Information Processing Systems (NIPS 2011)&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt;   year&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;span&gt;2011&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt;   organization&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;span&gt;Neural Information Processing Systems Foundation&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;All tags must be followed by a comma. Unfortunately, there was no comma after one of my author tags (above), which seems to be pretty common. Normally this isn&#39;t an issue, but the &lt;em&gt;IEEEtran&lt;/em&gt; bib-style can&#39;t handle minor syntactical issues without erroring out.&lt;/p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Slow MATLAB parfor (parallel for) performance and possible Parallel Toolbox bug</title>
        <published>2011-10-14T18:53:00+00:00</published>
        <updated>2011-10-14T18:53:00+00:00</updated>
        
        <author>
          <name>erik</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://99a75f26.erikriffs.pages.dev/matlab-parfor-performance/"/>
        <id>https://99a75f26.erikriffs.pages.dev/matlab-parfor-performance/</id>
        
        <content type="html" xml:base="https://99a75f26.erikriffs.pages.dev/matlab-parfor-performance/">&lt;p&gt;After playing with the MATLAB Parallel Computing Toolbox (r2009a x64), I noticed what appears to be significant overhead when writing to an array in parallel, increasing the speed of a parallel for loop by over an order of magnitude. This effect isn&#39;t observed in other programming languages like C, demonstrated below. While testing this, I also came across repeatable behavior indicative of a bug in MATLAB (see last code block). These tests were performed using a 4 core Intel i5 with 8GB of memory.&lt;/p&gt;
&lt;p&gt;First is a loop the sums the numbers from 1 to n, applying a reduction to the variable sum. This case is &lt;a rel=&quot;external&quot; title=&quot;embarrassingly parallel&quot; href=&quot;https://en.wikipedia.org/wiki/Embarrassingly_parallel&quot;&gt;embarrassingly parallel&lt;/a&gt; and shows a fairly linear increase in speed with respect to number of cores.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;matlab&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;n = &lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;10000000&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;sum=&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;0&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;fprintf&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;serial: &lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;tic&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;for&lt;/span&gt;&lt;span&gt; i=&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1&lt;/span&gt;&lt;span&gt;:n&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    sum = sum &lt;/span&gt;&lt;span&gt;+&lt;/span&gt;&lt;span&gt; i;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;toc&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;sum=&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;0&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;fprintf&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;parallel: &lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;tic&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;parfor&lt;/span&gt;&lt;span&gt; i=&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1&lt;/span&gt;&lt;span&gt;:n&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    sum = sum &lt;/span&gt;&lt;span&gt;+&lt;/span&gt;&lt;span&gt; i;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;toc&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;serial: Elapsed time is 8.241937 seconds.&lt;/p&gt;
&lt;p&gt;parallel: Elapsed time is 2.531207 seconds.&lt;/p&gt;
&lt;p&gt;Now, instead of using the loop counter to increment the variable sum, the elements of an array [1,2,…,n] are summed. This requires MATLAB to read from an array using 4 threads, one for each core. A linear speed increase is demonstrated (as expected) here as well.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;matlab&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;n = &lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;10000000&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;data = &lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1&lt;/span&gt;&lt;span&gt;:n; &lt;/span&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt; array with elements [1,2,...,n-1,n]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;sum=&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;0&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;fprintf&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;serial: &lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;tic&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;for&lt;/span&gt;&lt;span&gt; i=&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1&lt;/span&gt;&lt;span&gt;:n&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    sum = sum &lt;/span&gt;&lt;span&gt;+&lt;/span&gt;&lt;span&gt; data&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;i&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;toc&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;sum=&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;0&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;fprintf&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;parallel: &lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;tic&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;parfor&lt;/span&gt;&lt;span&gt; i=&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1&lt;/span&gt;&lt;span&gt;:n&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    sum = sum &lt;/span&gt;&lt;span&gt;+&lt;/span&gt;&lt;span&gt; data&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;i&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;toc&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;serial: Elapsed time is 9.642881 seconds.&lt;/p&gt;
&lt;p&gt;parallel: Elapsed time is 2.705653 seconds.&lt;/p&gt;
&lt;p&gt;Instead of reading from an array in parallel, an array is written to in parallel. Here there is a 7x slowdown when parallelizing the loop.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;matlab&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;n = &lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;10000000&lt;/span&gt;&lt;span&gt;; &lt;/span&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt; 10 million&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;data = zeros&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1&lt;/span&gt;&lt;span&gt;,n&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;fprintf&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;serial: &lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;tic&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;for&lt;/span&gt;&lt;span&gt; i=&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1&lt;/span&gt;&lt;span&gt;:n&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    data&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;i&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; = i;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;toc&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;data=zeros&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1&lt;/span&gt;&lt;span&gt;,n&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;fprintf&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;parallel: &lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;tic&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;parfor&lt;/span&gt;&lt;span&gt; i=&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1&lt;/span&gt;&lt;span&gt;:n&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    data&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;i&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; = i;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;toc&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;serial: Elapsed time is 0.618991 seconds.&lt;/p&gt;
&lt;p&gt;parallel: Elapsed time is 4.359711 seconds.&lt;/p&gt;
&lt;p&gt;Interestingly, this slowdown doesn&#39;t occur when using OpenMP in C; using multiple cores allows for a 26% speedup during the equivalent array allocation. This is not 4x since the majority of CPU time is spent waiting for the next cache line to be retrieved from memory since no time is spent computing.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;include&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;stdio.h&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;include&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;stdlib.h&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;include&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;omp.h&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;include&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;time.h&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt; main&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;z-d-9 z-d-i&quot;&gt; argc&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt; char&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;z-d-9 z-d-i&quot;&gt;argv&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;	int&lt;/span&gt;&lt;span&gt; n &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; 200000000&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt; //&lt;/span&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt;200 million&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;	int&lt;/span&gt;&lt;span&gt; i&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;	double&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;*&lt;/span&gt;&lt;span&gt; data &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt; malloc&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;n&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;sizeof&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;double&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;	clock_t&lt;/span&gt;&lt;span&gt; start &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt; clock&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; diff&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;	for&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;i&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;0&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;span&gt; i&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;n&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;span&gt; i&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;++&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-11 z-d-9&quot;&gt;		data&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span&gt;i&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt; =&lt;/span&gt;&lt;span&gt; i&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	diff &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt; clock&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt; -&lt;/span&gt;&lt;span&gt; start&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt;	free&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;data&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;	int&lt;/span&gt;&lt;span&gt; msec &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;=&lt;/span&gt;&lt;span&gt; diff &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; 1000&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt; /&lt;/span&gt;&lt;span&gt; CLOCKS_PER_SEC&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt;	printf&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;Serial: Time taken &lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;%d&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; seconds &lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;%d&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; milliseconds&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-1&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; msec&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1000&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; msec&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1000&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	data &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt; malloc&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;n&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;sizeof&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;double&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	start &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt; clock&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;	#&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;pragma&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; omp&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; parallel&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; for&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;	for&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;i&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;0&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;span&gt; i&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;n&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;span&gt; i&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;++&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-11 z-d-9&quot;&gt;		data&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span&gt;i&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt; =&lt;/span&gt;&lt;span&gt; i&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	diff &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt; clock&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt; -&lt;/span&gt;&lt;span&gt; start&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt;	free&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;data&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	msec &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;=&lt;/span&gt;&lt;span&gt; diff &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; 1000&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt; /&lt;/span&gt;&lt;span&gt; CLOCKS_PER_SEC&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-3 z-d-3&quot;&gt;	printf&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;Parallel: Time taken &lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;%d&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; seconds &lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;%d&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt; milliseconds&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; msec&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1000&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; msec&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1000&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;	return&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt; 0&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Serial: Time taken 1 seconds 583 milliseconds&lt;/p&gt;
&lt;p&gt;Parallel: Time taken 1 seconds 167 milliseconds&lt;/p&gt;
&lt;p&gt;Here is one additional observation which, by itself, leads me to believe there is some form of bug in the MATLAB Parallel Computing Toolbox. &lt;strong&gt;Introducing an additional variable before each loop slows the serial code by nearly 29x&lt;/strong&gt;. This doesn&#39;t make any sense as the variable isn&#39;t used in the loop and should have no effect on computation time whatsoever. But let&#39;s look at speed difference:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;matlab&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;clear&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;n = &lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;10000000&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;data = zeros&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1&lt;/span&gt;&lt;span&gt;,n&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;sum=&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;0&lt;/span&gt;&lt;span&gt;; &lt;/span&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt; new, unused variable&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;fprintf&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;serial: &lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;tic&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;for&lt;/span&gt;&lt;span&gt; i=&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1&lt;/span&gt;&lt;span&gt;:n&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    data&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;i&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; = i;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;toc&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;sum=&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;0&lt;/span&gt;&lt;span&gt;; &lt;/span&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;z-l-7 z-l-i z-d-4 z-d-i&quot;&gt; new, unused variable&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;data=zeros&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1&lt;/span&gt;&lt;span&gt;,n&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;fprintf&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;parallel: &lt;/span&gt;&lt;span class=&quot;z-l-4 z-d-5&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;tic&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;parfor&lt;/span&gt;&lt;span&gt; i=&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-8&quot;&gt;1&lt;/span&gt;&lt;span&gt;:n&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    data&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;i&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; = i;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-7&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;toc&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;serial: Elapsed time is 17.926449 seconds.&lt;/p&gt;
&lt;p&gt;parallel: Elapsed time is 4.477197 seconds.&lt;/p&gt;
&lt;p&gt;This behavior is consistent and replicable. Simply commenting out the &lt;code&gt;sum=0;&lt;/code&gt; radically changes the speed. There should be no difference, but try pasting the above code into a MATLAB editor and running the code, then the identical code without the &lt;code&gt;sum=0;&lt;/code&gt;. Further, pasting the code directly into the MATLAB terminal does not produce a difference in speed for the serial code; only running from a MATLAB editor window produces this anomaly.&lt;/p&gt;
</content>
        
    </entry>
</feed>
