class RedisClusterCacheBenchmark::Summary
Constants
- DEFAULT_POSITIONS
Public Class Methods
new(values, positions = DEFAULT_POSITIONS)
click to toggle source
@param [Array<Numeric>] values 整数あるいは実数の配列
# File lib/redis_cluster_cache_benchmark/summary.rb, line 8 def initialize(values, positions = DEFAULT_POSITIONS) values = values.sort cnt = values.empty? ? 0 : values.length sum = values.empty? ? 0 : values.inject(:+) @hash = { cnt: cnt, sum: sum, avg: (cnt == 0) ? 0 : sum / cnt, min: values.first || 0, max: values.last || 0, } positions.each do |pos| idx = (cnt * pos / 100).round @hash[pos.to_s.to_sym] = values[idx] || 0 end end
Public Instance Methods
[](key)
click to toggle source
# File lib/redis_cluster_cache_benchmark/summary.rb, line 33 def [](key) @hash[key.to_s.to_sym] end
each(&block)
click to toggle source
# File lib/redis_cluster_cache_benchmark/summary.rb, line 29 def each(&block) @hash.each(&block) end
to_hash()
click to toggle source
# File lib/redis_cluster_cache_benchmark/summary.rb, line 25 def to_hash @hash.dup end