Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

speed up root_filter #396

Merged
merged 3 commits into from
Aug 21, 2015
Merged
Changes from 1 commit
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: 1 addition & 1 deletion lib/simplecov/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
SimpleCov.profiles.define "root_filter" do
# Exclude all files outside of simplecov root
add_filter do |src|
!(src.filename =~ /^#{Regexp.escape(SimpleCov.root)}/i)
!src.filename.downcase.start_with?(SimpleCov.root.downcase)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to think if there's any chance src.filename might be nil

Also, can you try benchmarking with /^#{Regexp.escape(SimpleCov.root)}/io (the o means it will only compile the interpolated value once), and also maybe \A instead of ^, and also maybe ROOT_FILTER = /^{Regexp.escape(SimpleCov.root)}/i)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit surprised, regex solution is faster, but not because of the extraction and the o modifier but because of the \A change (which of course makes sense), but I did not expect that it will be faster than String#start_with?.

Calculating -------------------------------------
         start_with?   105.000  i/100ms
     match_optimized    14.000  i/100ms
   match_optimized_A   102.435k i/100ms
               match    13.000  i/100ms
-------------------------------------------------
         start_with?      1.110k (± 3.5%) i/s -      5.565k
     match_optimized    147.382  (± 6.1%) i/s -    742.000
   match_optimized_A      2.477M (± 6.6%) i/s -     12.395M
               match    143.284  (± 6.3%) i/s -    715.000

Comparison:
   match_optimized_A:  2477292.0 i/s
         start_with?:     1110.0 i/s - 2231.75x slower
     match_optimized:      147.4 i/s - 16808.64x slower
               match:      143.3 i/s - 17289.33x slower

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blog post? That's pretty interesting

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mind gisting your benchmark here? or maybe adding it to bench/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end
end

Expand Down