Class: RailsParallel::Timings
- Inherits:
-
Object
- Object
- RailsParallel::Timings
- Defined in:
- lib/rails_parallel/timings.rb
Constant Summary collapse
- TIMING_COUNT =
10
Instance Method Summary collapse
- #fetch(test_name, class_name) ⇒ Object
-
#initialize ⇒ Timings
constructor
A new instance of Timings.
- #record(test_name, class_name, time) ⇒ Object
Constructor Details
#initialize ⇒ Timings
Returns a new instance of Timings.
9 10 11 |
# File 'lib/rails_parallel/timings.rb', line 9 def initialize @cache = Redis.new end |
Instance Method Details
#fetch(test_name, class_name) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/rails_parallel/timings.rb', line 19 def fetch(test_name, class_name) key = key_for(test_name, class_name) times = @cache.lrange(key, 0, TIMING_COUNT - 1).map(&:to_f) return 0 if times.empty? times.sum / times.count end |
#record(test_name, class_name, time) ⇒ Object
13 14 15 16 17 |
# File 'lib/rails_parallel/timings.rb', line 13 def record(test_name, class_name, time) key = key_for(test_name, class_name) @cache.lpush(key, time) @cache.ltrim(key, 0, TIMING_COUNT - 1) end |