Class: PerfCheck
- Inherits:
-
Object
- Object
- PerfCheck
- Defined in:
- lib/perf_check.rb,
lib/perf_check/git.rb,
lib/perf_check/server.rb,
lib/perf_check/test_case.rb
Defined Under Namespace
Classes: Git, Server, TestCase
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#server ⇒ Object
Returns the value of attribute server.
-
#test_cases ⇒ Object
Returns the value of attribute test_cases.
Class Method Summary collapse
Instance Method Summary collapse
- #add_test_case(route) ⇒ Object
-
#initialize ⇒ PerfCheck
constructor
A new instance of PerfCheck.
- #print_results ⇒ Object
- #run ⇒ Object
- #sanity_check ⇒ Object
Constructor Details
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
11 12 13 |
# File 'lib/perf_check.rb', line 11 def @options end |
#server ⇒ Object
Returns the value of attribute server.
11 12 13 |
# File 'lib/perf_check.rb', line 11 def server @server end |
#test_cases ⇒ Object
Returns the value of attribute test_cases.
11 12 13 |
# File 'lib/perf_check.rb', line 11 def test_cases @test_cases end |
Class Method Details
.normalize_resource(resource) ⇒ Object
53 54 55 |
# File 'lib/perf_check/git.rb', line 53 def self.normalize_resource(resource) resource.sub(/^([^\/])/, '/\1') end |
Instance Method Details
#add_test_case(route) ⇒ Object
19 20 21 22 |
# File 'lib/perf_check.rb', line 19 def add_test_case(route) route = PerfCheck.normalize_resource(route) test_cases.push(TestCase.new(route)) end |
#print_results ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/perf_check.rb', line 55 def print_results puts("==== Results ====") test_cases.each do |test| puts(test.resource) if test.reference_latencies.empty? printf("your branch: ".rjust(15)+"%.1fms\n", test.this_latency) next end master_latency = sprintf('%.1fms', test.reference_latency) this_latency = sprintf('%.1fms', test.this_latency) difference = sprintf('%+.1fms', test.latency_difference) if test.latency_difference < 0 formatted_change = sprintf('%.1fx', test.latency_factor) formatted_change = "yours is #{formatted_change} faster!" else formatted_change = sprintf('%.1fx', 1.0 / test.latency_factor) formatted_change = "yours is #{formatted_change} slower!!!" end formatted_change = difference + " (#{formatted_change})" puts("master: ".rjust(15) + "#{master_latency}") puts("your branch: ".rjust(15)+ "#{this_latency}") puts("change: ".rjust(15) + "#{formatted_change}") end end |
#run ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/perf_check.rb', line 35 def run (.reference ? 2 : 1).times do |i| if i == 1 Git.stash_if_needed Git.checkout_reference(.reference) test_cases.each{ |x| x.latencies = x.reference_latencies } end test_cases.each do |test| server.restart if .login test. = server.login(.login, test) end puts("\n\nBenchmarking #{test.resource}:") test.run(server, .number_of_requests) end end end |
#sanity_check ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/perf_check.rb', line 24 def sanity_check if Git.current_branch == "master" puts("Yo, profiling master vs. master isn't too useful, but hey, we'll do it") end puts "="*77 print "PERRRRF CHERRRK! Grab a ☕️ and don't touch your working tree " puts "(we automate git)" puts "="*77 end |