From: shyouhei@... Date: 2018-04-18T07:57:15+00:00 Subject: [ruby-core:86573] [Ruby trunk Bug#14695] [2.5.1] `===` is 1.77x slower than `match?` Issue #14695 has been updated by shyouhei (Shyouhei Urabe). baweaver (Brandon Weaver) wrote: > It appears that `===` is running a bit slower than `match?` Accurate observation. Regexp#match? was introduced as a "faster alternative" to ordinary matches; see also https://bugs.ruby-lang.org/issues/8110 ---------------------------------------- Bug #14695: [2.5.1] `===` is 1.77x slower than `match?` https://bugs.ruby-lang.org/issues/14695#change-71512 * Author: baweaver (Brandon Weaver) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17] * Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN ---------------------------------------- Was evaluating some of the `===` implementations while testing and came across this one: ~~~ ruby # ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17] require 'benchmark/ips' def run_benchmark(title, **benchmarks) puts '', title, '=' * title.size, '' # Validation benchmarks.each do |benchmark_name, benchmark_fn| puts "#{benchmark_name} result: #{benchmark_fn.call()}" end puts Benchmark.ips do |bm| benchmarks.each do |benchmark_name, benchmark_fn| bm.report(benchmark_name, &benchmark_fn) end bm.compare! end end regex = /foo/ # => /foo/ string = 'foobarbaz' # => "foobarbaz" run_benchmark('=== vs match? - 2.5.1', '===': -> { regex === string }, 'match?': -> { regex.match? string } ) === vs match? - 2.5.1 ===================== === result: true match? result: true Warming up -------------------------------------- === 173.435k i/100ms match? 233.124k i/100ms Calculating ------------------------------------- === 3.174M (�� 1.6%) i/s - 15.956M in 5.029027s match? 5.626M (�� 2.5%) i/s - 28.208M in 5.016991s Comparison: match?: 5626170.1 i/s ===: 3173659.6 i/s - 1.77x slower ~~~ It appears that `===` is running a bit slower than `match?`, though there may be some concerns around old code potentially relying on regex set globals after `===` too in case statements, so not sure there. -- https://bugs.ruby-lang.org/ Unsubscribe: