RSpec profiler top-N output and slow threshold configuration
0 reputation · 30 Apr 2024, 23:15 UTC
RSpec's built-in profiler reports the N slowest examples and example groups after a run when enabled via --profile or config.profile_examples. The output includes location, description and elapsed wall-clock time per example, with timing that covers before/after hooks and let/subject evaluation.
The goal is to use profiling to identify bottlenecks before optimization. An open behavior concerns how the profiler decides what is shown and how configuration interacts with CLI options. When config.profile_examples is set to a positive integer, profiling is enabled by default, but the definition of "slow" is tied to the count of examples shown rather than an independent time threshold. Sorting is per individual example, not by cumulative group cost, so group-level overhead can be obscured.
Does the CLI --profile count override config.profile_examples when both are set, and which value takes precedence? Is there a separate time threshold for slow examples independent of the count shown? How is group cost represented when a slow before(:context) hook makes individual examples appear fast?