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


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="mpope" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  mpope
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Two micro optimizations that you can try:</p>
<ol>
<li>Try using guards instead of case + tuples to avoid tuple allocations.</li>
<li></li>
</ol>
<details>
<summary>
This one doesn't make sense I realized there's only one proc per range.</summary>
<p>You’re sending a message to initiate the calcuation. If you spawned a process that waits to receive a <code>print</code> you can eliminate the scheduling time needed for the self send. Could be splitting hairs but it’d make starting the calculation slightly faster.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def spawner(range) do
  spawn(
    fn -&gt;
      res = Fizzbuzz.fizzbuzz_no_io(range)
      receive do
        {:print, pid} -&gt;
          IO.binwrite(results)
          pid ! :done
      end
    end)
end
</code></pre>
<p>Sadly you’ll have to make a poor man’s <code>GenServer.call</code> with plain procs, but since its a microbenchmark it might be worth trying.</p>
</details>
<ol start="3">
<li>Try doubling the number of processes.</li>
</ol> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="294015" data-batch-url="/posts/batch_likers">
                        0
                      </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/question-regarding-improving-fizzbuzz-io-performance/56816/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-294015" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="294015"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="294018" data-post-id="294018">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="technusm1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/technusm1/120/31120_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  technusm1
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Thanks for your answer <a class="mention" href="/u/mpope" rel="nofollow">@mpope</a>. Regarding all the points 1-3:</p>
<ol>
<li>Try using guards instead of case + tuples to <strong>avoid tuple allocations</strong>: I tried with the following <code>reply</code> version, but over multiple runs I found out that sometimes its faster by a second from my original function and sometimes it is slower. So, I believe using this one won’t get us any speed improvements:</li>
</ol>
<pre data-code-wrap="elixir"><code class="lang-elixir">def reply(n) when rem(n, 15) == 0, do: "FizzBuzz\n"
def reply(n) when rem(n, 3) == 0, do: "Fizz\n"
def reply(n) when rem(n, 5) == 0, do: "Buzz\n"
def reply(n), do: [Integer.to_string(n), "\n"]
</code></pre>
<p>Still I’m keeping this, because I think reducing tuple allocations is a good idea. Thanks for this one!</p>
<ol start="2">
<li>
<p>I believe this is similar to using a cast instead of a call as suggested in an earlier comment. And I believe a call is the better option here because when we’re using multiple processes in BEAM, a process can be pre-empted at any instant. Take a case for instance - I have 2 processes - P1 and P2 and I have sent a <code>:print</code> message to P1 and then to P2. It is quite possible that process P1 (which was supposed to print first) got pre-empted at that instant, while P2 was not. As a result, P2 could end up processing <code>:print</code> message first and thus make IO call before P1. Just try changing the call to cast and you’ll observe that the output is no longer being printed in order. Even if both the processes were running on different cores of our CPU, its quite possible that there are speed differences between different cores (ARM’s BIG-LITTLE processors come to mind here).</p>
</li>
<li>
<p>Try doubling the number of processes. Tried that by doubling max_concurrency in <code>Task.async_stream</code>, getting inconsistent results on repeated runs like number 1, sometimes its marginally faster and sometimes it is marginally slower. So, I believe this won’t get us any improvements either.</p>
</li>
</ol>
<p>Thanks for your help.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="294018" 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/question-regarding-improving-fizzbuzz-io-performance/56816/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-294018" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="294018"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="295025" data-post-id="295025">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="technusm1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/technusm1/120/31120_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  technusm1
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Back here with another optimization: Setting <code>Fizzbuzz.Worker</code> <code>GenServer</code>’s state to a binary instead of an iolist in <code>handle_info</code>. Ultimately, we’ll be passing a binary to our IO process. But since our binary is quite large (a refc binary), it should reduce message passing overhead. I made this change after going through erlang’s efficiency guide <a href="https://www.erlang.org/doc/efficiency_guide/processes.html#sending-messages" rel="nofollow">here</a>. According to it:</p>
<blockquote>
<p>All data in messages sent between Erlang processes is copied, except for <a href="https://www.erlang.org/doc/efficiency_guide/binaryhandling.html#refc_binary" rel="nofollow">refc binaries</a> and <a href="https://www.erlang.org/doc/efficiency_guide/processes.html#literal-pool" rel="nofollow">literals</a> on the same Erlang node.</p>
</blockquote>
<p>This change improves the throughput to 225 MiB/s.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="295025" data-batch-url="/posts/batch_likers">
                        0
                      </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/question-regarding-improving-fizzbuzz-io-performance/56816/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-295025" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="295025"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="295038" data-post-id="295038">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Can you show the exact code? This sounds intriguing.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="295038" data-batch-url="/posts/batch_likers">
                        0
                      </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/question-regarding-improving-fizzbuzz-io-performance/56816/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-295038" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="295038"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="295069" data-post-id="295069">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="technusm1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/technusm1/120/31120_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  technusm1
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Oops, my bad. I meant that I have changed the state of my Fizzbuzz.Worker module from an iolist to a binary. Since the resultant binary is definitely greater than 64 bytes for large enough inputs, it’s safe to say I’m creating a refc binary (and passing that to IO.binwrite when calling print). Here’s the changed module:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Fizzbuzz.Worker do
  use GenServer

  def init([range]) do
    send(self(), {:calculate, range})
    {:ok, []}
  end

  def handle_info({:calculate, range}, _state) do
    res = Fizzbuzz.fizzbuzz_no_io(range)
    {:noreply, res |&gt; :erlang.iolist_to_binary} # &lt;-- changed the state here
  end

  def handle_call(:print, _from, results) do
    IO.binwrite(results) # &lt;-- refc binary gets passed here.
    {:reply, :ok, []}
  end
end
</code></pre>
<p>Passing a large binary instead of an iolist to IO reduces message passing overhead, which improves the overall throughput</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="295069" 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/question-regarding-improving-fizzbuzz-io-performance/56816/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-295069" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="295069"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #15"></div>
  </section>
</div>
    <div class="postbit" id="295431" data-post-id="295431">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="technusm1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/technusm1/120/31120_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  technusm1
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>OK, I got one more trick to get further performance boost on unix-based systems: directly writing to <code>/dev/stdout</code>, which brings the performance to around 500 MiB/s on my MacBook Pro. Its a shame there’s no alternative for Windows. <img src="https://forum.elixirforum.com/images/emoji/apple/slightly_frowning_face.png?v=15" title=":slightly_frowning_face:" class="emoji" alt=":slightly_frowning_face:" loading="lazy" width="20" height="20"></p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def handle_call(:print, _from, results) do
  # /dev/stdout is UNIX only, so this won't work on windows
  case :os.type() do
    {:unix, _} -&gt;
      {:ok, io_device} = :file.open("/dev/stdout", [:append, :raw])
      :ok = :file.write(io_device, results)
      :file.close(io_device)
    _ -&gt; IO.binwrite(results)
  end
  {:reply, :ok, []}
end
</code></pre>
<p>The speed is quite unstable though, ranging between 400-700 MiB/s. But the 5-minute average speed comes around to 500 MiB/s.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="295431" data-batch-url="/posts/batch_likers">
                        0
                      </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/question-regarding-improving-fizzbuzz-io-performance/56816/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-295431" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="295431"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #16"></div>
  </section>
</div>
    <div class="postbit" id="295456" data-post-id="295456">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="mpope" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  mpope
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Does <code>IO.binwrite</code> send a message to a process? Using raw file access means that no process communication happens, which could be saving time. <em>maybe</em> try this raw stdout access without flattening the binary, because iirc when you set the state in <code>handle_info</code> that isn’t a message pass to itself. I think state transitions are optimized.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="295456" data-batch-url="/posts/batch_likers">
                        2
                      </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/question-regarding-improving-fizzbuzz-io-performance/56816/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-295456" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="295456"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-most-liked cat-most-liked" title="One of the top 3 liked posts in this thread!"></div>
  </section>
</div>
    <div class="postbit" id="295462" data-post-id="295462">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>What is the reason for having separate process for printing?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="295462" data-batch-url="/posts/batch_likers">
                        0
                      </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/question-regarding-improving-fizzbuzz-io-performance/56816/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-295462" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="295462"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #18"></div>
  </section>
</div>
    <div class="postbit" id="295468" data-post-id="295468">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I couldn’t run your code, it would be handy to have it as a gist or repo somewhere so it would be easier to test against it, but my approach was to reduce the amount of messages being sent as much as possible, so I just use port directly instead of going through some additional hops. It also avoids congestion on single process that happens in case of <code>IO.binwrite/1</code> or <code>IO.stream</code> (though it can cause some artifacts, like output being printed out of order):</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule FizzBuzz do
  @compile {:inline, fb_fast: 1}

  def main do
    schedulers = System.schedulers_online()

    for i &lt;- 0..schedulers do
      Process.spawn(fn -&gt;
        port = :erlang.open_port({:fd, 0, 1}, [:binary, :out])

        chunk(port, i + 1, schedulers)
      end, priority: :high)
    end

    Process.sleep(:timer.minutes(1))
  end

  defp chunk(port, n, step) do
    send(port, {self(), {:command, fb_fast(n)}})
    chunk(port, n + step, step)
  end

  defp fb_fast(n) do
    for i &lt;- 0..3000 do
    """
    #{n+i}
    #{n+i+1}
    Fizz
    #{n+i+3}
    Buzz
    #{n+i+5}
    #{n+i+6}
    #{n+i+7}
    Fizz
    Buzz
    #{n+i+10}
    Fizz
    #{n+i+12}
    #{n+i+13}
    FizzBuzz
    """
    end
  end
end

FizzBuzz.main()
</code></pre>
<p>I haven’t tested it extensively, but it is fast enough IMHO.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="295468" 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/question-regarding-improving-fizzbuzz-io-performance/56816/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-295468" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="295468"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #19"></div>
  </section>
</div>
    <div class="postbit" id="295501" data-post-id="295501">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="technusm1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/technusm1/120/31120_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  technusm1
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a class="mention" href="/u/mpope" rel="nofollow">@mpope</a> that it correct and its what I’m doing I believe. I don’t understand the part about <em><strong>trying this raw stdout access without flattening the binary</strong></em> though, could you elaborate further?</p>
<p>However, I made one small optimization from looking at your post and reading <strong>Concurrent Data Processing in Elixir by Svilen Gospodinov</strong> though, replacing <code>handle_info</code> with <code>handle_continue</code>, which should get rid of the self message passing.</p>
<p><a class="mention" href="/u/hauleth" rel="nofollow">@hauleth</a> you’re the man! The port approach in your program above works as good as directly writing to <code>/dev/stdout</code> and I’m getting speeds in range of 490 - 520 MiB/s on average. Now, to answer your questions:</p>
<blockquote>
<p>What is the reason for having separate process for printing?</p>
</blockquote>
<p>The separate processes are for improving computation speed, printing from them is just a necessity. My approach too, was to reduce message passing as much as possible, and print the results in order. So, I’m spinning up several Genservers and dividing the work between them. The genservers hold their results till I send them print command (in order) to print their computed results. Earlier, I was using Tasks for doing the computations and then sending back the results to main process and then printing them in order, but that was unnecessary message passing, since tasks return results to the caller, which we’re then sending to IO.</p>
<blockquote>
<p>I couldn’t run your code, it would be handy to have it as a gist or repo somewhere so it would be easier to test against it</p>
</blockquote>
<p>Here you go: <a href="https://github.com/technusm1/fizzbuzz/" rel="noopener nofollow ugc">technusm1/fizzbuzz (github.com)</a>. I’m sorry I didn’t post this until now, probably because I’m unashamedly violating almost every good version control and software design practices for this program.</p>
<p>On that note, I also have a bit outdated writeup of all the things I did for Fizzbuzz on my blog: <a href="https://maheepk.net/posts/fizzbuzz-on-elixir/" class="inline-onebox" rel="noopener nofollow ugc">Fizz Buzz Pro on Elixir | Maheep's Webspace</a></p>
<p>Lastly, I also benchmarked your code and I’m getting speeds around 350-420 MiB/s. Like you said, its fast enough, and simple enough too. But it does print out of order (printing in order is a hard requirement). Nonetheless, I learned a lot from it and I’m keeping it.</p>
<p>Thanks!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="295501" 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/question-regarding-improving-fizzbuzz-io-performance/56816/21">Post #20</a>
	                </div>
	            </div>
              <div id="likers-container-295501" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="295501"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #20"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/56816/load_more?page=3">Load more posts (8 remaining)</a>
</div></template></turbo-stream>