Posted in Development

Ruby gems: Writing one for Powershop

During the last two weeks at Powershop I wrote and published one of my first gems as part of a development task. The gem is called Stopwatch and can be found on GitHub and RubyGems. For a bit of context, recently we had a performance issue with a couple of pages that made them take a few seconds to load. The performance issue was O(N), proportional to how long a customer has been with us. When trying to fix the issue, we also want to prevent it from being introduced again—that’s where Stopwatch comes in. The gem allows you to write automated tests that assert the run time of some task (e.g., loading a page). The idea was that we could write a test as follows: expect { get :index }.to run_for < 0.5.seconds The gem’s RSpec matcher, run_for, will 1) discard a warmup run of the task, 2) time multiple runs of the task and 3) average the run times. While this worked as expected, we have so far encountered […]