Patch #28939

replace regexp with casecmp

Added by Pavel Rosický about 1 year ago. Updated about 1 year ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Performance
Target version:-

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

database.rb.patch Magnifier (840 Bytes) Pavel Rosický, 2018-06-04 00:30

nested_set.patch Magnifier (1.02 KB) Pavel Rosický, 2018-06-04 00:49


Related issues

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

History

#1 Updated by Pavel Rosický about 1 year ago

#2 Updated by Go MAEDA about 1 year 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" 

#3 Updated by Pavel Rosický about 1 year 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

#4 Updated by Go MAEDA about 1 year ago

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

#5 Updated by Go MAEDA about 1 year 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.

Also available in: Atom PDF