Last active
August 29, 2015 14:01
-
-
Save tgxworld/51b0ed1fbc220a0c168f to your computer and use it in GitHub Desktop.
Sample test file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'abstract_unit' | |
require 'benchmark' | |
require 'benchmark/ips' | |
require 'ruby-prof' | |
class AController < ActionController::Base | |
def index | |
render html: 'ok' | |
end | |
end | |
class AControllerTest < ActionController::TestCase | |
def test_profile | |
get :index | |
assert_equal 'ok', response.body | |
end | |
end | |
class AController1Test < ActionDispatch::IntegrationTest | |
def test_profile | |
get 'https://www.example.com/a/index' | |
assert_equal 'ok', response.body | |
end | |
end | |
Benchmark.bm(30) do |bm| | |
bm.report 'Slow' do | |
RubyProf.start | |
400.times do | |
Minitest.run_one_method(AController1Test, 'test_profile') | |
end | |
results = RubyProf.stop | |
File.open "a.html", 'w' do |file| | |
RubyProf::GraphHtmlPrinter.new(results).print(file) | |
end | |
end | |
bm.report 'Fast' do | |
Minitest.run_one_method(AController1Test, 'test_profile') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment