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 #2

Updated by Go MAEDA over 6 years ago

The proposed patch does not work for MySQL adapter because its name is "Mysql2". I think using exact match against adapter names is not a good solution.

irb(main):001:0> ActiveRecord::Base.connection.adapter_name
=> "Mysql2" 
Actions #3

Updated by Pavel Rosický over 6 years ago

  • Status changed from New to Resolved

ah, sorry. I totaly forgot about this case. I used match? insted in
http://www.redmine.org/issues/28940

so the behaviour won't be changed. Closing this one

Actions #4

Updated by Go MAEDA over 6 years ago

  • Related to Patch #28940: Use Regexp#match? to reduce allocations of MatchData object added
Actions #5

Updated by Go MAEDA over 6 years ago

  • Status changed from Resolved to Closed

Pavel Rosický wrote:

I used match? insted in
http://www.redmine.org/issues/28940

Closing this issue because #28940 covers this improvement. Thank you.

Actions

Also available in: Atom PDF