Profiling RSpec examples with Stackprof
13 Oct 2015
Finding out why a particular spec is slow might be tricky.
Thanks to Aman Gupta, we have stackprof - a sampling call-stack profiler for ruby 2.1+.
I have used it a lot while working on RubyBench and finding slow parts of code in Rails stack, but never in specs.
Yesterday I had to find out why my RSpec example was slow and I wrote this snippet:
This snippet profiles every example block in your test file and saves the dump into
tmp/, for instance
Later, you can use
bundle exec stackprof to analize the dump.
In my case, stackprof helped me to realize that most of the time in specs was spent on SASS compilation:
NB: you do not need to keep the profiling enabled all the time. Use the snippet only when you need to debug a specific case.