Here we’ll talk about two distinct ways to test the execution speed of code. Benchmarking measures the overall speed of the code, while profiling gives more detailed information about how long different parts of the code take to execute, relative to each other.
The previous variants all showed ways to modify the base code in the hopes of making it faster. Here’s where we test our assumptions and find out what really makes a difference. I store it in a directory called
tests, meaning that I run it with
ruby -w tests/test_opts.rb.
#!/usr/bin/env ruby # test_opts.rb =begin comment Run this without warnings to avoid messages about method redefinition, which we are doing intentionally ...