プロジェクト

全般

プロフィール

Vote #76570

完了

Use String#casecmp for case insensitive comparison

Admin Redmine さんが3年以上前に追加. 3年以上前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Code cleanup/refactoring_30
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
30
version_id:
102
issue_org_id:
20369
author_id:
332
assigned_to_id:
0
comments:
4
status_id:
5
tracker_id:
3
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[Closed]

説明

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

journals

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Committed in trunk r14484, thanks.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------


related_issues

relates,Closed,20278,Wrong syntax for resizing inline images will throw a 500 error
relates,Closed,27780,Case-insensitive matching fails for Unicode filenames when referring to attachments in text formatting

Admin Redmine さんが3年以上前に更新

  • カテゴリCode cleanup/refactoring_30 にセット
  • 対象バージョン3.2.0_102 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0