Class: Benchmarker::Result
- Inherits:
-
Object
- Object
- Benchmarker::Result
- Defined in:
- lib/benchmarker.rb
Instance Method Summary collapse
- #[](idx) ⇒ Object
- #add(timeset) ⇒ Object
- #calc_average ⇒ Object
- #clear ⇒ Object
- #each(&b) ⇒ Object
-
#initialize ⇒ Result
constructor
A new instance of Result.
- #length ⇒ Object
- #remove_minmax(extra, key = :real) ⇒ Object
- #skipped=(reason) ⇒ Object
- #skipped? ⇒ Boolean
Constructor Details
#initialize ⇒ Result
Returns a new instance of Result.
616 617 618 |
# File 'lib/benchmarker.rb', line 616 def initialize() @iterations = [] end |
Instance Method Details
#[](idx) ⇒ Object
620 621 622 |
# File 'lib/benchmarker.rb', line 620 def [](idx) return @iterations[idx] end |
#add(timeset) ⇒ Object
632 633 634 635 636 |
# File 'lib/benchmarker.rb', line 632 def add(timeset) #; [!thyms] adds timeset and returns self. @iterations << timeset self end |
#calc_average ⇒ Object
671 672 673 674 675 676 677 678 679 680 681 682 |
# File 'lib/benchmarker.rb', line 671 def calc_average() #; [!b91w3] returns average of timeddata. user = sys = total = real = 0.0 @iterations.each do |t| user += t.user sys += t.sys total += t.total real += t.real end n = @iterations.length return TimeSet.new(user/n, sys/n, total/n, real/n) end |
#clear ⇒ Object
638 639 640 641 642 |
# File 'lib/benchmarker.rb', line 638 def clear() #; [!fxrn6] clears timeset array. @iterations.clear() self end |
#each(&b) ⇒ Object
628 629 630 |
# File 'lib/benchmarker.rb', line 628 def each(&b) @iterations.each(&b) end |
#length ⇒ Object
624 625 626 |
# File 'lib/benchmarker.rb', line 624 def length() return @iterations.length end |
#remove_minmax(extra, key = :real) ⇒ Object
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 |
# File 'lib/benchmarker.rb', line 653 def remove_minmax(extra, key=:real) #; [!b55zh] removes best and worst timeset and returns them. i = 0 pairs = @iterations.collect {|t| [t, i+=1] } pairs = pairs.sort_by {|pair| pair[0].__send__(key) } removed = [] extra.times do min_timeset, min_idx = pairs.shift() max_timeset, max_idx = pairs.pop() min_t = min_timeset.__send__(key) max_t = max_timeset.__send__(key) removed << [min_t, min_idx, max_t, max_idx] end remained = pairs.sort_by {|_, i| i }.collect {|t, _| t } @iterations = remained return removed end |
#skipped=(reason) ⇒ Object
644 645 646 |
# File 'lib/benchmarker.rb', line 644 def skipped=(reason) @reason = reason end |
#skipped? ⇒ Boolean
648 649 650 651 |
# File 'lib/benchmarker.rb', line 648 def skipped? #; [!bvzk9] returns true if reason has set, or returns false. return !!@reason end |