Skip to content

Commit

Permalink
stats.rb: make cache for is_failure and is_latency
Browse files Browse the repository at this point in the history
$ ruby -r profile sbin/compare -a 4633c9e07b3b7d7fc262a5f59ff635c1f702af6f

Before:
  %   cumulative   self              self     total
 time   seconds   seconds    calls  ms/call  ms/call  name
 11.50     0.33      0.33    12750     0.03     0.07  Object#is_failure
  8.36     0.89      0.24    11375     0.02     0.08  Object#is_latency

After: (is_failure and is_latency cache)
  %   cumulative   self              self     total
 time   seconds   seconds    calls  ms/call  ms/call  name
  1.39     1.39      0.03     1945     0.02     0.05  Object#is_failure
  1.39     1.33      0.03     2099     0.01     0.03  Object#is_latency

Signed-off-by: Wanlong Gao <[email protected]>
Signed-off-by: Fengguang Wu <[email protected]>
  • Loading branch information
gaowanlong authored and Fengguang Wu committed Jun 15, 2015
1 parent 0c8e271 commit 2e91023
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,16 +270,28 @@ def load_base_matrix(matrix_path, head_matrix)
end
end

def is_failure(stats_field)
def __is_failure(stats_field)
$metric_failure.each { |pattern| return true if stats_field =~ %r{^#{pattern}} }
return false
end

def is_latency(stats_field)
def is_failure(stats_field)
$__is_failure_cache ||= {}
$__is_failure_cache[stats_field] ||= __is_failure(stats_field)
return $__is_failure_cache[stats_field]
end

def __is_latency(stats_field)
$metric_latency.each { |pattern| return true if stats_field =~ %r{^#{pattern}} }
return false
end

def is_latency(stats_field)
$__is_latency_cache ||= {}
$__is_latency_cache[stats_field] ||= __is_latency(stats_field)
return $__is_latency_cache[stats_field]
end

def should_add_max_latency(stats_field)
$metric_add_max_latency.each { |pattern| return true if stats_field =~ %r{^#{pattern}$} }
return false
Expand Down

0 comments on commit 2e91023

Please sign in to comment.