Create a gist now

Instantly share code, notes, and snippets.

Demonstration of object allocation improvements in RSpec 3.2

This repository demonstrates the difference in object allocations between rspec-core 3.1 and 3.2. See output for the results of running example_spec.rb while tracking object allocations on 3.1 and 3.2.

  • 3.1: 134745
  • 3.2: 91816
  • Difference: 42929

That's a 31.9% reduction in allocations between RSpec 3.1 and 3.2.

require 'allocation_stats'
require 'rspec/core'
stats = AllocationStats.new.trace do
10.times do |i|
RSpec.describe "Group #{i}" do
10.times do |j|
it("example #{j}") { }
context "nested group #{j}" do
10.times do |k|
it("example #{k}") { }
end
end
end
end
end
RSpec::Core::Runner.invoke
end
puts stats.allocations.group_by().to_text
source "https://rubygems.org"
gem 'rspec-core', "~> 3.1.7"
gem 'allocation_stats'
GEM
remote: https://rubygems.org/
specs:
allocation_stats (0.1.5)
rspec-core (3.1.7)
rspec-support (~> 3.1.0)
rspec-support (3.1.2)
PLATFORMS
ruby
DEPENDENCIES
allocation_stats
rspec-core (~> 3.1.7)
source "https://rubygems.org"
gem 'rspec-core', "~> 3.2.0"
gem 'allocation_stats'
GEM
remote: https://rubygems.org/
specs:
allocation_stats (0.1.5)
rspec-core (3.2.0)
rspec-support (~> 3.2.0)
rspec-support (3.2.0)
PLATFORMS
ruby
DEPENDENCIES
allocation_stats
rspec-core (~> 3.2.0)
➜ rspec-allocations git:(master) time BUNDLE_GEMFILE=Gemfile-3-1 bundle exec ruby example_spec.rb
............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Finished in 0.20442 seconds (files took 0.23812 seconds to load)
1100 examples, 0 failures
count
-----
134745
BUNDLE_GEMFILE=Gemfile-3-1 bundle exec ruby example_spec.rb 1.45s user 0.13s system 99% cpu 1.590 total
➜ rspec-allocations git:(master) time BUNDLE_GEMFILE=Gemfile-3-2 bundle exec ruby example_spec.rb
............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Finished in 0.20653 seconds (files took 0.18637 seconds to load)
1100 examples, 0 failures
count
-----
91816
BUNDLE_GEMFILE=Gemfile-3-2 bundle exec ruby example_spec.rb 1.21s user 0.11s system 99% cpu 1.329 total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment