Performance deep dive

Bob
Bob in Rust

In this approach, we'll find out how to most efficiently determine the response for Bob in Rust.

The approaches page lists two idiomatic approaches to this exercise:

  1. Using if statements.
  2. Using match on a tuple.

For our performance investigation, we'll also include a third approach that uses an answer array.

Benchmarks

To benchmark the approaches, we wrote a small benchmark application.

test multiple_line_question_match  ... bench:          96 ns/iter (+/- 17)
test multiple_line_question_if     ... bench:          97 ns/iter (+/- 12)
test multiple_line_question_array  ... bench:         100 ns/iter (+/- 2)

All three approaches are close in performance, but the if statements and match approaches may be considered to be more idiomatic.

28th Aug 2024 · Found it useful?