Project

General

Profile

Actions

Patch #28939

closed

replace regexp with casecmp

Added by Pavel Rosický over 6 years ago. Updated over 6 years ago.

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

0%

Estimated time:

Description

require 'benchmark/ips'
Benchmark.ips do |x|
  x.report('casecmp') { 'PostgreSql'.casecmp('postgresql') == 0 }
  x.report('match')   { 'PostgreSql' =~ /postgresql/i }
  x.report('match?')  { 'PostgreSql'.match? /postgresql/i }
  x.compare!
end
Comparsion:
casecmp:  4218477.8 i/s
 match?:  3025829.3 i/s - 1.39x  slower
  match:  2222223.1 i/s - 1.90x  slower

Files

database.rb.patch (840 Bytes) database.rb.patch Pavel Rosický, 2018-06-04 00:30
nested_set.patch (1.02 KB) nested_set.patch Pavel Rosický, 2018-06-04 00:49

Related issues

Related to Redmine - Patch #28940: Use Regexp#match? to reduce allocations of MatchData objectClosedGo MAEDA

Actions
Actions

Also available in: Atom PDF