From 4b2912abc4a83c924c07b593badce70c409776b1 Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Thu, 19 Jul 2018 16:28:40 +0300 Subject: [PATCH] Remove `String#casecmp` rule Because this method doesn't work with Unicode, and `#downcase` does (since Ruby 2.4). --- README.md | 18 ------------------ code/string/casecmp-vs-downcase-==.rb | 17 ----------------- 2 files changed, 35 deletions(-) delete mode 100644 code/string/casecmp-vs-downcase-==.rb diff --git a/README.md b/README.md index 677a7a9..8952926 100644 --- a/README.md +++ b/README.md @@ -1007,24 +1007,6 @@ $ ruby -v code/string/dup-vs-unary-plus.rb String#dup: 3566485.7 i/s - 2.16x slower ``` -##### `String#casecmp` vs `String#downcase + ==` [code](code/string/casecmp-vs-downcase-==.rb) - -``` -$ ruby -v code/string/casecmp-vs-downcase-\=\=.rb -ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14] - -Calculating ------------------------------------- -String#downcase + == 101.900k i/100ms - String#casecmp 109.828k i/100ms -------------------------------------------------- -String#downcase + == 2.915M (± 5.4%) i/s - 14.572M - String#casecmp 3.708M (± 6.1%) i/s - 18.561M - -Comparison: - String#casecmp: 3708258.7 i/s -String#downcase + ==: 2914767.7 i/s - 1.27x slower -``` - ##### String Concatenation [code](code/string/concatenation.rb) ``` diff --git a/code/string/casecmp-vs-downcase-==.rb b/code/string/casecmp-vs-downcase-==.rb deleted file mode 100644 index 027f748..0000000 --- a/code/string/casecmp-vs-downcase-==.rb +++ /dev/null @@ -1,17 +0,0 @@ -require 'benchmark/ips' - -SLUG = 'ABCD' - -def slow - SLUG.downcase == 'abcd' -end - -def fast - SLUG.casecmp('abcd') == 0 -end - -Benchmark.ips do |x| - x.report('String#downcase + ==') { slow } - x.report('String#casecmp') { fast } - x.compare! -end