Reputation: 1912
I am working to improve one of my own gems. I would like to be able to get some data on the magnitude of improvement (if any) of the various ideas I come up.
Normally I test using the benchmark/ips facility.
So I would like to load the old version of my gem and the new one for the purpose of conducting side-by-side tests.
I don't know how to load two versions of the same gem and have them apply selectively as needed.
So far my best idea is to clone the old gem, and build a local copy with an altered name like "old_gem_name". Then load that for comparison purposes.
Is there a better way?
Upvotes: 0
Views: 117
Reputation: 1228
I would approach this using two different Gemfiles.
So assuming you have a benchmark.rb
file that has the following:
# benchmark.rb
require 'benchmark'
puts Benchmark.measure { 1000.times{ call_to_gem_method} }
Then with your two different Gemfiles, one called Gemfile-oldgem
and the other called Gemfile-newgem
, you do the following:
# Gemfile-oldgem
gem "mygem", :path => "/path/to/oldgem/mygem"
Run this for the old gem benchmark:
BUNDLE_GEMFILE=Gemfile-oldgem bundle exec ruby benchmark.rb
And for the new gem you have:
# Gemfile-newgem
gem "mygem", :path => "/path/to/newgem/mygem"
Run this to benchmark it:
BUNDLE_GEMFILE=Gemfile-newgem bundle exec ruby benchmark.rb
Upvotes: 2