Project

General

Profile

Actions

Bug #736

closed

Range#include? が遅い

Added by rubikitch (rubikitch .) over 16 years ago. Updated over 12 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
Backport:

Description

=begin
Ruby 1.9でRange#include?がものすごい遅いようです。

require 'benchmark'
RUBY_VERSION # => "1.8.7"
Benchmark.bmbm(10) do |b|
n = 100
b.report("include") { n.times{ ("an".."ruby").include? "elf" }}
b.report("between") { n.times{ "elf".between?("an","ruby") }}
end

>> Rehearsal ---------------------------------------------

>> include 0.000000 0.000000 0.000000 ( 0.000278)

>> between 0.000000 0.000000 0.000000 ( 0.000113)

>> ------------------------------------ total: 0.000000sec

>>

>> user system total real

>> include 0.000000 0.000000 0.000000 ( 0.000233)

>> between 0.000000 0.000000 0.000000 ( 0.000113)

require 'benchmark'
RUBY_VERSION # => "1.9.0"
Benchmark.bmbm(10) do |b|
n = 100
b.report("include") { n.times{ ("an".."ruby").include? "elf" }}
b.report("between") { n.times{ "elf".between?("an","ruby") }}
end

>> Rehearsal ---------------------------------------------

>> include 0.420000 0.000000 0.420000 ( 0.417621)

>> between 0.000000 0.000000 0.000000 ( 0.000116)

>> ------------------------------------ total: 0.420000sec

>>

>> user system total real

>> include 0.420000 0.000000 0.420000 ( 0.422576)

>> between 0.000000 0.000000 0.000000 ( 0.000120)

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0