Skip to content

Instantly share code, notes, and snippets.

@alloy
Last active April 30, 2021 11:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alloy/6249335 to your computer and use it in GitHub Desktop.
Save alloy/6249335 to your computer and use it in GitHub Desktop.
RSpec boot times vs smaller test frameworks.
$:.unshift(File.expand_path('..', __FILE__))
require 'bowling'
describe Bowling, "#score" do
it "returns 0 for all gutter game" do
bowling = Bowling.new
20.times { bowling.hit(0) }
bowling.score.should == 0
end
end
class Bowling
def hit(pins)
end
def score
0
end
end
$:.unshift(File.expand_path('..', __FILE__))
require 'bowling'
describe Bowling, "#score" do
it "returns 0 for all gutter game" do
bowling = Bowling.new
20.times { bowling.hit(0) }
bowling.score.should == 0
end
end
~/t/rspec-vs-small » ruby -v
ruby 1.9.3p385 (2013-02-06 revision 39114) [x86_64-darwin12.2.0]
~/t/rspec-vs-small » gem install rspec peck bacon
Successfully installed rspec-2.14.1
Successfully installed peck-0.3.0
Successfully installed bacon-1.2.0
3 gems installed
~/t/rspec-vs-small » ruby time.rb
Bacon: 0.2515
Peck: 0.26
RSpec: 0.39749999999999996
$:.unshift(File.expand_path('..', __FILE__))
require 'bowling'
describe Bowling, "#score" do
it "returns 0 for all gutter game" do
bowling = Bowling.new
20.times { bowling.hit(0) }
bowling.score.should eq(0)
end
end
require 'open3'
SAMPLE_SIZE = 20
def time(*command)
total = 0
SAMPLE_SIZE.times do
_, __, stderr = Open3.popen3('time', '-p', *command)
output = stderr.gets(nil)
line = output.strip.split("\n")[-3]
real = line.match(/\d\.\d\d/)[0]
total += real.to_f
end
total / SAMPLE_SIZE
end
STDOUT.sync = true
print "Bacon: "
puts time('bacon', 'bacon_example.rb')
print "Peck: "
puts time('ruby', '-r', 'rubygems', '-r', 'peck/flavors/vanilla', 'peck_example.rb')
print "RSpec: "
puts time('rspec', 'rspec_example.rb')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment