I created an Ruby gem rspec test to write performance tests in RSpec. There are many expectations for testing speed, resource utilization and scalability.
For example, to check how fast your code works:
expect { ... }.to perform_under(60).ms
Or compare with another implementation:
expect { ... }.to perform_faster_than { ... }.at_least(5).times
Or check the computational complexity:
expect { ... }.to perform_logarithmic.in_range(8, 100_000)
Or see how many objects are selected:
expect { _a = [Object.new] _b = {Object.new => 'foo'} }.to perform_allocation({Array => 1, Object => 2}).objects
Piotr murach
source share