Project

General

Profile

Actions

Patch #20369

closed

Use String#casecmp for case insensitive comparison

Added by Go MAEDA over 8 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Code cleanup/refactoring
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:

Description

String#casecmp is faster than String#downcase. We can save some CPU cycles by replacing String#downcase with String#casecmp.

The following is a script to benchmark.

#!/usr/bin/env ruby

def measure(p)
  t1 = Time.now
  1000000.times {p.call}
  t2 = Time.now
  t2 - t1
end

str1 = (1..100).map {('A'..'z').to_a.sample}.join
str2 = str1.downcase

puts "String#casecmp  :  #{measure(->{ str1.casecmp(str2) == 0})} sec" 
puts "String#downcase :  #{measure(->{ str1.downcase == str2 })} sec" 

Here is a result. casecmp is remarkably faster than downcase.

laphroaig:patches maeda$ ruby casecmp-vs-downcase.rb
String#casecmp  :  0.358929 sec
String#downcase :  0.557218 sec

Files


Related issues

Related to Redmine - Defect #20278: Wrong syntax for resizing inline images will throw a 500 errorClosedJean-Philippe Lang

Actions
Related to Redmine - Defect #27780: Case-insensitive matching fails for Unicode filenames when referring to attachments in text formattingClosedGo MAEDA

Actions
Actions #1

Updated by Toshi MARUYAMA over 8 years ago

  • Target version set to 3.2.0
Actions #2

Updated by Go MAEDA over 8 years ago

  • Related to Defect #20278: Wrong syntax for resizing inline images will throw a 500 error added
Actions #3

Updated by Toshi MARUYAMA over 8 years ago

  • Status changed from New to Closed

Committed in trunk r14484, thanks.

Actions #4

Updated by Go MAEDA over 6 years ago

  • Related to Defect #27780: Case-insensitive matching fails for Unicode filenames when referring to attachments in text formatting added
Actions

Also available in: Atom PDF