Skip to content

Instantly share code, notes, and snippets.

@cheald
Created October 23, 2012 15:48
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 cheald/3939582 to your computer and use it in GitHub Desktop.
Save cheald/3939582 to your computer and use it in GitHub Desktop.
RSpec.configure do |c|
def profile
result = RubyProf.profile { yield }
name = example.metadata[:full_description].downcase.gsub(/[^a-z0-9_-]/, "-").gsub(/-+/, "-")
printer = RubyProf::CallTreePrinter.new(result)
open("tmp/performance/callgrind.#{name}.#{Time.now.to_i}.trace", "w") do |f|
printer.print(f)
end
end
c.around(:each) do |example|
if ENV['PROFILE'] == 'all' or (example.metadata[:profile] and ENV['PROFILE'])
profile { example.run }
else
example.run
end
end
end
describe "A test" do
it "can be profiled", :profile => true do
expect { some_complex_operation }.to_not raise_error
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment