avatarThe Pragmatic Programmers

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1138

Abstract

on the BEAM, which was designed for telecommunication systems. This doesn’t mean you can’t write performant genetic algorithms in Elixir; it means you need to be deliberate in optimizing those algorithms.</p><p id="e220">The BEAM is the Erlang virtual machine. It’s the core of Erlang/OTP. Every Elixir file compiles to BEAM bytecode. The best way to understand the performance of your applications is to understand what happens when your application compiles and runs the BEAM bytecode. This chapter will briefly cover some aspects of the BEAM; however, the material isn’t comprehensive by any means. For a fantastic explanation of the internals of the BEAM, check out The BEAM Book.<a href="https://readmedium.com/what-you-learned-2a063b5606d3">[14]</a></p><p id="25c9">In this chapter, you’ll learn how to benchmark and profile your algorithms, and you’ll briefly learn about where performance really matters. Additionally, you’ll learn different ways to optimize your algorithms. We’ll walk through a series of optimizations, in the following order:</p><ol><li>Creating benchmarks and profiling your algorithms.</li><li>Optimizing the

Options

performance of Elixir code.</li><li>Parallelizing your algorithms.</li><li>Writing NIFS.</li></ol><p id="4c40">When working through optimizations, this is generally the order of optimizations you should make — only progressing to the next step when absolutely necessary.</p><p id="2d00"><i>👈 <a href="https://readmedium.com/what-you-learned-558f65085768">What You Learned</a> | <a href="https://readmedium.com/table-of-contents-879fc8614df">TOC</a> | <a href="https://readmedium.com/benchmarking-and-profiling-genetic-algorithms-e2b864a1d375">Benchmarking and Profiling Genetic Algorithms</a> 👉</i></p><p id="965c"><i>Genetic Algorithms in Elixir by Sean Moriarity can be purchased in other book formats <a href="https://pragprog.com/titles/smgaelixir">directly from the Pragmatic Programmers</a>. If you notice a code error or formatting mistake, please let us know <a href="https://readmedium.com/how-to-report-errata-4e164674347a">here</a> so that we can fix it.</i></p><figure id="5777"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*U2E2a23SuM4520w9CUXSWw.jpeg"><figcaption></figcaption></figure></article></body>

Chapter 11 Optimizing Your Algorithms

Genetic Algorithms in Elixir — by Sean Moriarity (81 / 101)

👈 What You Learned | TOC | Benchmarking and Profiling Genetic Algorithms 👉

Thus far, you haven’t needed to worry too much about the performance of the algorithms you’ve implemented. The solutions have been small, and you’ve been working with relatively small populations. Because of this, you haven’t needed to be concerned with efficiency. In the real world, you’ll often need to deal with significantly larger solutions and populations when applying genetic algorithms to practical problems.

As it turns out, Elixir is a language that wasn’t designed to be extremely efficient at computationally expensive tasks. Things like floating-point math and matrix multiplication are slow in Elixir. Elixir runs on the BEAM, which was designed for telecommunication systems. This doesn’t mean you can’t write performant genetic algorithms in Elixir; it means you need to be deliberate in optimizing those algorithms.

The BEAM is the Erlang virtual machine. It’s the core of Erlang/OTP. Every Elixir file compiles to BEAM bytecode. The best way to understand the performance of your applications is to understand what happens when your application compiles and runs the BEAM bytecode. This chapter will briefly cover some aspects of the BEAM; however, the material isn’t comprehensive by any means. For a fantastic explanation of the internals of the BEAM, check out The BEAM Book.[14]

In this chapter, you’ll learn how to benchmark and profile your algorithms, and you’ll briefly learn about where performance really matters. Additionally, you’ll learn different ways to optimize your algorithms. We’ll walk through a series of optimizations, in the following order:

  1. Creating benchmarks and profiling your algorithms.
  2. Optimizing the performance of Elixir code.
  3. Parallelizing your algorithms.
  4. Writing NIFS.

When working through optimizations, this is generally the order of optimizations you should make — only progressing to the next step when absolutely necessary.

👈 What You Learned | TOC | Benchmarking and Profiling Genetic Algorithms 👉

Genetic Algorithms in Elixir by Sean Moriarity can be purchased in other book formats directly from the Pragmatic Programmers. If you notice a code error or formatting mistake, please let us know here so that we can fix it.

Smgaelixir
Recommended from ReadMedium