<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="https://baszerr.eu/lib/exe/css.php?s=feed" type="text/css"?>
<rss version="2.0">
    <channel xmlns:g="http://base.google.com/ns/1.0">
        <title>BaSzErr - blog:2013:03:14</title>
        <description></description>
        <link>https://baszerr.eu/</link>
        <lastBuildDate>Sun, 03 May 2026 14:43:11 +0000</lastBuildDate>
        <generator>FeedCreator 1.8</generator>
        <image>
            <url>https://baszerr.eu/lib/exe/fetch.php?media=wiki:dokuwiki.svg</url>
            <title>BaSzErr</title>
            <link>https://baszerr.eu/</link>
        </image>
        <item>
            <title>vector_vs_list</title>
            <link>https://baszerr.eu/doku.php?id=blog:2013:03:14:vector_vs_list</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;vector_vs_list&quot;&gt;2013.03.14 - vector&amp;lt;&amp;gt; vs. list&amp;lt;&amp;gt;&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
almost exactly year ago &lt;a href=&quot;https://en.wikipedia.org/wiki/Bjarne Stroustrup&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/Bjarne Stroustrup&quot;&gt;Bjarne&lt;/a&gt; had a &lt;a href=&quot;http://channel9.msdn.com/Events/GoingNative/GoingNative-2012/Keynote-Bjarne-Stroustrup-Cpp11-Style&quot; class=&quot;urlextern&quot; title=&quot;http://channel9.msdn.com/Events/GoingNative/GoingNative-2012/Keynote-Bjarne-Stroustrup-Cpp11-Style&quot; rel=&quot;ugc nofollow&quot;&gt;C++11 style&lt;/a&gt; presentation in &lt;a href=&quot;https://en.wikipedia.org/wiki/Wrocław&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/Wrocław&quot;&gt;Wrocław&lt;/a&gt;. aside from many interesting pieces of information, there was very nice example of how &lt;a href=&quot;https://baszerr.eu/doku.php?id=docs:cache_usage_effects_on_modern_cpus:cache_usage_effects_on_modern_cpus&quot; class=&quot;wikilink1&quot; title=&quot;docs:cache_usage_effects_on_modern_cpus:cache_usage_effects_on_modern_cpus&quot; data-wiki-id=&quot;docs:cache_usage_effects_on_modern_cpus:cache_usage_effects_on_modern_cpus&quot;&gt;CPU caches and memory access&lt;/a&gt; affect applications&amp;#039; runtime, on modern hardware.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;2013.03.14 - vector&amp;lt;&amp;gt; vs. list&amp;lt;&amp;gt;&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;vector_vs_list&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;1-504&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit2&quot; id=&quot;algorithm&quot;&gt;algorithm&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
the algorithm is simple: insert N random elements to a container, so that it remains sorted all the time. after that, N times remove 1 element, from a random position. the question is: which container will be faster? &lt;a href=&quot;http://en.cppreference.com/w/cpp/container/list&quot; class=&quot;urlextern&quot; title=&quot;http://en.cppreference.com/w/cpp/container/list&quot; rel=&quot;ugc nofollow&quot;&gt;list&lt;/a&gt; or &lt;a href=&quot;http://en.cppreference.com/w/cpp/container/vector&quot; class=&quot;urlextern&quot; title=&quot;http://en.cppreference.com/w/cpp/container/vector&quot; rel=&quot;ugc nofollow&quot;&gt;vector&lt;/a&gt;? how big N will be the breaking point, where list is faster than vector? the answer is: never! due to constant cache misses, when using list, and constant cache hits, when using vector, the former one outperforms the other for all Ns!
&lt;/p&gt;

&lt;p&gt;
recently i was doing a training/presentation, on cache and memory effects, for colleagues at work, and was not believed it is, as Bjarne suggested. “how come moving thousands of elements is faster than iteration over list nodes”? well it is. but of course we do not take anything on one&amp;#039;s word – we &lt;a href=&quot;https://baszerr.eu/doku.php?id=blog:2012:04:06:1&quot; class=&quot;wikilink1&quot; title=&quot;blog:2012:04:06:1&quot; data-wiki-id=&quot;blog:2012:04:06:1&quot;&gt;do measure&lt;/a&gt; instead.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;algorithm&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;algorithm&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;505-1445&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit3&quot; id=&quot;implementation&quot;&gt;implementation&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
code implemented in C++, along with makefile for automatic generating images from gathered results, are &lt;a href=&quot;https://baszerr.eu/lib/exe/fetch.php?media=blog:2013:03:14:vector_vs_list.tar.bz2&quot; class=&quot;media mediafile mf_bz2&quot; title=&quot;blog:2013:03:14:vector_vs_list.tar.bz2 (1.7 KB)&quot;&gt;available for download&lt;/a&gt;. for the reference, my test code follows:
&lt;/p&gt;
&lt;pre class=&quot;code cpp&quot;&gt;&lt;span class=&quot;co1&quot;&gt;//&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;// implemented by BaSz @ 2013/q2&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;//&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;// g++-4.7 -Wall -std=c++11 -O3 -DNDEBUG -march=native -o vector_vs_list.out vector_vs_list.cpp&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;//&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;list&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;vector&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;chrono&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;random&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;iomanip&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;iostream&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;typeinfo&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;algorithm&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;cinttypes&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;cassert&amp;gt;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;namespace&lt;/span&gt; std&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw4&quot;&gt;typedef&lt;/span&gt; chrono&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;high_resolution_clock&lt;/span&gt; Clock&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw4&quot;&gt;typedef&lt;/span&gt; std&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;sy1&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;uint64_t&lt;/span&gt;&lt;span class=&quot;sy1&quot;&gt;&amp;gt;&lt;/span&gt;   List&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;typedef&lt;/span&gt; std&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;vector&lt;/span&gt;&lt;span class=&quot;sy1&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;uint64_t&lt;/span&gt;&lt;span class=&quot;sy1&quot;&gt;&amp;gt;&lt;/span&gt; Vector&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;sy1&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;typename&lt;/span&gt; C, &lt;span class=&quot;kw2&quot;&gt;typename&lt;/span&gt; R&lt;span class=&quot;sy1&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;uint64_t&lt;/span&gt; algo&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;R r, &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;uint64_t&lt;/span&gt; n&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  C                      c&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kw2&quot;&gt;typename&lt;/span&gt; C&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;value_type&lt;/span&gt; out &lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span class=&quot;co1&quot;&gt;// insertion&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;uint64_t&lt;/span&gt; i&lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt; i&lt;span class=&quot;sy1&quot;&gt;&amp;lt;&lt;/span&gt;n&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;sy2&quot;&gt;++&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;auto&lt;/span&gt; x  &lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt; r&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kw4&quot;&gt;auto&lt;/span&gt;       it &lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt; c.&lt;span class=&quot;me1&quot;&gt;begin&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt; it&lt;span class=&quot;sy3&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt;c.&lt;span class=&quot;me1&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;sy3&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;sy2&quot;&gt;*&lt;/span&gt;it&lt;span class=&quot;sy1&quot;&gt;&amp;lt;&lt;/span&gt;x &lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
      &lt;span class=&quot;sy2&quot;&gt;++&lt;/span&gt;it&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
    c.&lt;span class=&quot;me1&quot;&gt;insert&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;it, x&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
    out&lt;span class=&quot;sy2&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt;x&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
  &lt;span class=&quot;co1&quot;&gt;// sanity check&lt;/span&gt;
  &lt;span class=&quot;kw3&quot;&gt;assert&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt; is_sorted&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt; c.&lt;span class=&quot;me1&quot;&gt;cbegin&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;, c.&lt;span class=&quot;me1&quot;&gt;cend&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span class=&quot;co1&quot;&gt;// removal&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;uint64_t&lt;/span&gt; i&lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt; i&lt;span class=&quot;sy1&quot;&gt;&amp;lt;&lt;/span&gt;n&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;sy2&quot;&gt;++&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;auto&lt;/span&gt; pos &lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt; r&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;sy2&quot;&gt;%&lt;/span&gt; c.&lt;span class=&quot;me1&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kw4&quot;&gt;auto&lt;/span&gt;       it  &lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt; c.&lt;span class=&quot;me1&quot;&gt;begin&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;uint64_t&lt;/span&gt; i&lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt; i&lt;span class=&quot;sy1&quot;&gt;&amp;lt;&lt;/span&gt;pos&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;sy2&quot;&gt;++&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
      &lt;span class=&quot;sy2&quot;&gt;++&lt;/span&gt;it&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
    out&lt;span class=&quot;sy2&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sy2&quot;&gt;*&lt;/span&gt;it&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
    c.&lt;span class=&quot;me1&quot;&gt;erase&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;it&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
  &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; out&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;sy1&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;typename&lt;/span&gt; C&lt;span class=&quot;sy1&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; run&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;uint64_t&lt;/span&gt; n, &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;uint64_t&lt;/span&gt; seed&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&quot;co1&quot;&gt;// prepare rand&lt;/span&gt;
  mt19937                            gen&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;seed&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  uniform_int_distribution&lt;span class=&quot;sy1&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;uint64_t&lt;/span&gt;&lt;span class=&quot;sy1&quot;&gt;&amp;gt;&lt;/span&gt; dist&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;, n&lt;span class=&quot;sy2&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kw4&quot;&gt;auto&lt;/span&gt;                               r &lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;sy3&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; dist&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;gen&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;co1&quot;&gt;// work&lt;/span&gt;
  &lt;span class=&quot;kw4&quot;&gt;auto&lt;/span&gt; start &lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt; Clock&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;now&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kw4&quot;&gt;auto&lt;/span&gt; ret   &lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt; algo&lt;span class=&quot;sy1&quot;&gt;&amp;lt;&lt;/span&gt;C&lt;span class=&quot;sy1&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;r, n&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kw4&quot;&gt;auto&lt;/span&gt; stop  &lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt; Clock&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;now&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;co1&quot;&gt;// info&lt;/span&gt;
  &lt;span class=&quot;kw4&quot;&gt;auto&lt;/span&gt; diff  &lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt; stop&lt;span class=&quot;sy2&quot;&gt;-&lt;/span&gt;start&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kw3&quot;&gt;cerr&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;typeid&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;C&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot; = &amp;quot;&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; fixed &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; setprecision&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
       &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; chrono&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;duration_cast&lt;/span&gt;&lt;span class=&quot;sy1&quot;&gt;&amp;lt;&lt;/span&gt;chrono&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;microseconds&lt;/span&gt;&lt;span class=&quot;sy1&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;diff&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy2&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;sy2&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;nu16&quot;&gt;1000.0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
       &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot; [s] (xxx==&amp;quot;&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; ret&lt;span class=&quot;sy2&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;nu19&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;)&lt;span class=&quot;es1&quot;&gt;\t&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&amp;nbsp;
&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; main&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&quot;co1&quot;&gt;// initilize generator with some seed&lt;/span&gt;
  std&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;random_device&lt;/span&gt; rd&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;auto&lt;/span&gt;         initSeed &lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt; rd&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  mt19937            gen&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;initSeed&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kw3&quot;&gt;cerr&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;&amp;gt;&amp;gt; initial seed = &amp;quot;&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; initSeed &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; endl&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;uint64_t&lt;/span&gt; n&lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt; n&lt;span class=&quot;sy1&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;sy2&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;sy2&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1000l&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt; n&lt;span class=&quot;sy2&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;2000&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;auto&lt;/span&gt; seed &lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt; gen&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kw3&quot;&gt;cerr&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;N = &amp;quot;&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; n &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;&lt;span class=&quot;es1&quot;&gt;\t&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
    run&lt;span class=&quot;sy1&quot;&gt;&amp;lt;&lt;/span&gt;List&lt;span class=&quot;sy1&quot;&gt;&amp;gt;&lt;/span&gt;  &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;n, seed&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
    run&lt;span class=&quot;sy1&quot;&gt;&amp;lt;&lt;/span&gt;Vector&lt;span class=&quot;sy1&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;n, seed&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kw3&quot;&gt;cerr&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot; &lt;span class=&quot;es1&quot;&gt;\t&lt;/span&gt; (for seed &amp;quot;&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; seed &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;)&amp;quot;&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; endl&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
  &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;implementation&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;implementation&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;1446-3816&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit4&quot; id=&quot;results&quot;&gt;results&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
results were obtained from 4, random runs. figures are grouped in a “full” and “begin” sets. each run is presented on a separate figure. click on images to enlarge them.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;results&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;results&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;3817-4009&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit5&quot; id=&quot;full&quot;&gt;full&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
set “full” contains all data gathered, from N=0 to N=80k.
&lt;/p&gt;

&lt;p&gt;
&lt;a href=&quot;https://baszerr.eu/lib/exe/detail.php?id=blog%3A2013%3A03%3A14%3Avector_vs_list&amp;amp;media=blog:2013:03:14:out1-full.png&quot; class=&quot;media&quot; title=&quot;blog:2013:03:14:out1-full.png&quot;&gt;&lt;img src=&quot;https://baszerr.eu/lib/exe/fetch.php?w=200&amp;amp;tok=13dcc6&amp;amp;media=blog:2013:03:14:out1-full.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; title=&quot;run 1 / full&quot; alt=&quot;run 1 / full&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;
&lt;a href=&quot;https://baszerr.eu/lib/exe/detail.php?id=blog%3A2013%3A03%3A14%3Avector_vs_list&amp;amp;media=blog:2013:03:14:out2-full.png&quot; class=&quot;media&quot; title=&quot;blog:2013:03:14:out2-full.png&quot;&gt;&lt;img src=&quot;https://baszerr.eu/lib/exe/fetch.php?w=200&amp;amp;tok=e344c6&amp;amp;media=blog:2013:03:14:out2-full.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; title=&quot;run 2 / full&quot; alt=&quot;run 2 / full&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;
&lt;a href=&quot;https://baszerr.eu/lib/exe/detail.php?id=blog%3A2013%3A03%3A14%3Avector_vs_list&amp;amp;media=blog:2013:03:14:out3-full.png&quot; class=&quot;media&quot; title=&quot;blog:2013:03:14:out3-full.png&quot;&gt;&lt;img src=&quot;https://baszerr.eu/lib/exe/fetch.php?w=200&amp;amp;tok=f2d61d&amp;amp;media=blog:2013:03:14:out3-full.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; title=&quot;run 3 / full&quot; alt=&quot;run 3 / full&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;
&lt;a href=&quot;https://baszerr.eu/lib/exe/detail.php?id=blog%3A2013%3A03%3A14%3Avector_vs_list&amp;amp;media=blog:2013:03:14:out4-full.png&quot; class=&quot;media&quot; title=&quot;blog:2013:03:14:out4-full.png&quot;&gt;&lt;img src=&quot;https://baszerr.eu/lib/exe/fetch.php?w=200&amp;amp;tok=4c881a&amp;amp;media=blog:2013:03:14:out4-full.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; title=&quot;run 4 / full&quot; alt=&quot;run 4 / full&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;full&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;full&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:5,&amp;quot;range&amp;quot;:&amp;quot;4010-4293&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit6&quot; id=&quot;begin&quot;&gt;begin&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
set “begin” shows just first 25% of obtained data, to show how does pictures look for small Ns.
&lt;/p&gt;

&lt;p&gt;
&lt;a href=&quot;https://baszerr.eu/lib/exe/detail.php?id=blog%3A2013%3A03%3A14%3Avector_vs_list&amp;amp;media=blog:2013:03:14:out1-begin.png&quot; class=&quot;media&quot; title=&quot;blog:2013:03:14:out1-begin.png&quot;&gt;&lt;img src=&quot;https://baszerr.eu/lib/exe/fetch.php?w=200&amp;amp;tok=207889&amp;amp;media=blog:2013:03:14:out1-begin.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; title=&quot;run 1 / begin&quot; alt=&quot;run 1 / begin&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;
&lt;a href=&quot;https://baszerr.eu/lib/exe/detail.php?id=blog%3A2013%3A03%3A14%3Avector_vs_list&amp;amp;media=blog:2013:03:14:out2-begin.png&quot; class=&quot;media&quot; title=&quot;blog:2013:03:14:out2-begin.png&quot;&gt;&lt;img src=&quot;https://baszerr.eu/lib/exe/fetch.php?w=200&amp;amp;tok=312e9a&amp;amp;media=blog:2013:03:14:out2-begin.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; title=&quot;run 2 / begin&quot; alt=&quot;run 2 / begin&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;
&lt;a href=&quot;https://baszerr.eu/lib/exe/detail.php?id=blog%3A2013%3A03%3A14%3Avector_vs_list&amp;amp;media=blog:2013:03:14:out3-begin.png&quot; class=&quot;media&quot; title=&quot;blog:2013:03:14:out3-begin.png&quot;&gt;&lt;img src=&quot;https://baszerr.eu/lib/exe/fetch.php?w=200&amp;amp;tok=86e37b&amp;amp;media=blog:2013:03:14:out3-begin.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; title=&quot;run 3 / begin&quot; alt=&quot;run 3 / begin&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;
&lt;a href=&quot;https://baszerr.eu/lib/exe/detail.php?id=blog%3A2013%3A03%3A14%3Avector_vs_list&amp;amp;media=blog:2013:03:14:out4-begin.png&quot; class=&quot;media&quot; title=&quot;blog:2013:03:14:out4-begin.png&quot;&gt;&lt;img src=&quot;https://baszerr.eu/lib/exe/fetch.php?w=200&amp;amp;tok=220ef7&amp;amp;media=blog:2013:03:14:out4-begin.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; title=&quot;run 4 / begin&quot; alt=&quot;run 4 / begin&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;begin&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;begin&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:6,&amp;quot;range&amp;quot;:&amp;quot;4294-4624&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit7&quot; id=&quot;conclusion&quot;&gt;conclusion&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
Bjarne did not lie. this statement is true for over 10 years now. as CPUs become constantly way faster than memory, the gap increases over time.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;conclusion&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;conclusion&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:7,&amp;quot;range&amp;quot;:&amp;quot;4625-&amp;quot;} --&gt;</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Tue, 15 Jun 2021 20:09:03 +0000</pubDate>
        </item>
    </channel>
</rss>
