Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replacing regular expression with string comparison
Based on benchmarking, string comparison is faster than regular express. I also believe that `end_with?(".")` reads better than mentally parsing a regular expression; It is certainly more "new developer" friendly. Here is the benchmark that I ran locally to test performance: ```ruby require 'benchmark' n = 30_000_000 Benchmark.bm do |x| x.report { n.times { ".".end_with?(".") } } x.report { n.times { "." =~ /\.$/ } } end ``` And here are the results: ```log user system total real 4.108148 0.021553 4.129701 ( 4.194707) 7.508562 0.018433 7.526995 ( 7.585707) ``` And as a bonus, when attempting to bump Rubocop's `TargetRubyVersion` from `2.3` to `2.4`, the one violation was that we were using `=~`. Rubocop recommended that we switch to `match?` for regular expressions.
- Loading branch information
Showing
3 changed files
with
4 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters