Project

General

Profile

Actions

Patch #40010

closed

Replace regular expression matches with String#start_with? / end_with?

Added by Go MAEDA 4 months ago. Updated 4 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Performance
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:

Description

The attached patch replaces regular expression matches with String#start_with? and String#end_with?.

The change improves the efficiency and readability of the code.

ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
Warming up --------------------------------------
'#123'.start_with?('#')
                         2.218M i/100ms
 /^#/.match?('#123')     1.322M i/100ms
Calculating -------------------------------------
'#123'.start_with?('#')
                         22.494M (± 1.0%) i/s -    113.141M in   5.030336s
 /^#/.match?('#123')     13.208M (± 0.8%) i/s -     66.089M in   5.003943s

Comparison:
'#123'.start_with?('#'): 22494308.6 i/s
 /^#/.match?('#123'): 13208263.3 i/s - 1.70x  slower

Files

start_end_with.patch (7.9 KB) start_end_with.patch Go MAEDA, 2024-01-07 05:35
Actions #1

Updated by Go MAEDA 4 months ago

  • Subject changed from Replace regular expression matches with start_with? / end_with? to Replace regular expression matches with String#start_with? / end_with?
  • Status changed from New to Closed
  • Assignee set to Go MAEDA

Commited the patch in r22605.

Actions

Also available in: Atom PDF