Class: RedisClusterCacheBenchmark::Summary
- Inherits:
-
Object
- Object
- RedisClusterCacheBenchmark::Summary
- Includes:
- Enumerable
- Defined in:
- lib/redis_cluster_cache_benchmark/summary.rb
Constant Summary collapse
- DEFAULT_POSITIONS =
[99, 95, 90, 80, 50].freeze
Instance Method Summary collapse
- #[](key) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(values, positions = DEFAULT_POSITIONS) ⇒ Summary
constructor
A new instance of Summary.
- #to_hash ⇒ Object
Constructor Details
#initialize(values, positions = DEFAULT_POSITIONS) ⇒ Summary
Returns a new instance of Summary.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/redis_cluster_cache_benchmark/summary.rb', line 9 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 |
Instance Method Details
#[](key) ⇒ Object
34 35 36 |
# File 'lib/redis_cluster_cache_benchmark/summary.rb', line 34 def [](key) @hash[key.to_s.to_sym] end |
#each(&block) ⇒ Object
30 31 32 |
# File 'lib/redis_cluster_cache_benchmark/summary.rb', line 30 def each(&block) @hash.each(&block) end |
#to_hash ⇒ Object
26 27 28 |
# File 'lib/redis_cluster_cache_benchmark/summary.rb', line 26 def to_hash @hash.dup end |