<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="104560" data-post-id="104560">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="OvermindDL1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/OvermindDL1/120/2677_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  OvermindDL1
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="Qqwy" data-post="11" data-topic="17985">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/qqwy/48/1349_2.png" class="avatar"> Qqwy:</div>
<blockquote>
<p>Done! The <a href="https://hex.pm/packages/orderable" rel="nofollow">orderable </a> library has been built, tested, documented and published.</p>
</blockquote>
</aside>
<p>Just because I find it fun, this is why I don’t like Elixir’s protocol implementation…  ^.^;<br>
I implemented the same trivial protocol implementation with protocol_ex with full optimizations enabled (though not bothered setting priority of callbacks or anything, it’s almost a 1-to-1 copy of the <code>orderable</code> protocol and implementations) and this is the benchmark using the <code>Rating</code> object from the readme of that project (yes there is a test to ensure they generate identical output for identical input) in a Tuple of 1000 <code>Rating</code>s:</p>
<pre><code class="lang-plaintext">╰─➤  mix bench ordered
Compiling 1 file (.ex)
Operating System: Linux"
CPU Information: AMD Phenom(tm) II X6 1090T Processor
Number of Available Cores: 6
Available memory: 15.67 GB
Elixir 1.7.4
Erlang 21.1.1

Benchmark suite executing with the following configuration:
warmup: 5 s
time: 5 s
memory time: 0 μs
parallel: 1
inputs: tuples
Estimated total run time: 20 s


Benchmarking Orderable with input tuples...
Benchmarking OrderableEx with input tuples...

##### With input tuples #####
Name                  ips        average  deviation         median         99th %
OrderableEx        2.67 K      375.12 μs    ±12.98%         361 μs         459 μs
Orderable          1.22 K      821.59 μs     ±9.05%         803 μs      993.54 μs

Comparison: 
OrderableEx        2.67 K
Orderable          1.22 K - 2.19x slower
</code></pre>
<p>Elixir protocols could have such a more efficient implementation…  ^.^;</p>
<p>With some slight optimizations of Rating itself (the rating_index part to be specific, using proper constant mappings instead of a map) I got them both up to:</p>
<pre><code class="lang-plaintext">##### With input tuples #####
Name                  ips        average  deviation         median         99th %
OrderableEx        3.03 K      330.57 μs    ±16.23%         313 μs         427 μs
Orderable          1.32 K      757.94 μs    ±13.54%         742 μs         946 μs

Comparison: 
OrderableEx        3.03 K
Orderable          1.32 K - 2.29x slower
</code></pre>
<p>I did multiple runs of each benchmark and always got the same instruction counts and ratio, no real variance.</p>
<p>And if you think that’s fast, you should see my ‘Access’ replacement.  ^.^</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="104560" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-implement-complexed-custom-sort/17985/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-104560" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="104560"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>