Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### Unreleased

* (patch) RSpec: Speed up the time tracker formatter by recording test path timings in place instead of rebuilding the whole collection after each top-level example group.

### 10.0.1

* Add support for [File Paths Encryption](https://docs.knapsackpro.com/ruby/encryption/) to [Retry only Failures](https://docs.knapsackpro.com/ruby/retry-only-failures/).
Expand Down
14 changes: 13 additions & 1 deletion lib/knapsack_pro/formatters/time_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def example_group_finished(notification)

add_hooks_time(@group, @time_all_by_group_id_path)
@time_all_by_group_id_path = Hash.new(0)
@paths = merge(@paths, @group)
merge_into(@paths, @group)
@group = {}
end

Expand Down Expand Up @@ -198,6 +198,18 @@ def merge(h1, h2)
end
end

# `merge` rebuilds the whole accumulator, which is quadratic when called
# once per top level group, so accumulate in place instead.
def merge_into(accumulator, other)
other.each do |path, example|
if accumulator.key?(path)
accumulator[path][:time_execution] += example[:time_execution]
else
accumulator[path] = example
end
end
end

def now
KnapsackPro::Utils.time_now
end
Expand Down