Search⌘ K

Using Benchee to Analyze Performance

Explore how to use Benchee to benchmark core functions of your genetic algorithm framework in Elixir. Learn to establish performance baselines, analyze memory and execution times, and identify areas for optimization in your algorithms. This lesson guides you through setting up benchmarks with a dummy problem to measure key function performance effectively.

Adding Benchee to the framework

If the optimization seems necessary, the first thing to do is establish a baseline.

Benchee is an Elixir benchmarking package that’s easy to use and provides a lot of information out of the box. We’ll use Benchee to benchmark the different aspects of our genetic algorithms.

We will start by adding Benchee to our dependencies in mix.exs:

C++
defp deps do
# ... other deps
{:benchee, ~> "1.0.1"}
end

Next, we will create a new file benchmark.exs in a new directory bench. We’ll declare the basic benchmarks of each of our core functions in this file.

Benchmarks are typically done on large parts of programs. In this example, we’ll benchmark each of the core functions in your genetic algorithm framework, and we’ll also benchmark a single evolution. To do this, we need to declare a DummyProblem that serves as a baseline problem for ...