Issue #12996 has been updated by ksss (Yuki Kurihara).

File range_eqq2.patch added

I updated the patch (range_eqq2.patch).

It optimize only special cases.

---

# Range with Fixnum

~~~
i = 0
while i < 10_000_000
  case i
  when 1..1000
  end
  i += 1
end
~~~

## Before

~~~
$ time ./miniruby t.rb
./miniruby t.rb  5.27s user 0.02s system 98% cpu 5.354 total
~~~

## After

~~~
$ time ./miniruby t.rb
./miniruby t.rb  4.45s user 0.04s system 96% cpu 4.644 total
~~~

---

# Range with String

~~~
i = 0
while i < 10_000_000
  case "c"
  when "a".."z"
  end
  i += 1
end
~~~

## Before

~~~
$ time ./miniruby t.rb
./miniruby t.rb  8.45s user 0.02s system 99% cpu 8.534 total
~~~

## After

~~~
$ time ./miniruby t.rb
./miniruby t.rb  3.80s user 0.01s system 98% cpu 3.874 total
~~~

---

Of course, test-all passed.

~~~
$ make test-all TESTS=test/ruby/test_range.rb
./tool/ifchange "--timestamp=.rbconfig.time" rbconfig.rb rbconfig.tmp
rbconfig.rb unchanged
creating verconf.h
verconf.h updated
compiling loadpath.c
linking static-library libruby.2.5.0-static.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: libruby.2.5.0-static.a(debug_counter.o) has no symbols
linking shared-library libruby.2.5.0.dylib
linking ruby
Run options: "--ruby=./miniruby -I./lib -I. -I.ext/common  ./tool/runruby.rb --extout=.ext  -- --disable-gems" --excludes-dir=./test/excludes --name=!/memory_leak/

# Running tests:

Finished tests in 2.777357s, 14.7622 tests/s, 144652.6320 assertions/s.
41 tests, 401752 assertions, 0 failures, 0 errors, 0 skips

ruby -v: ruby 2.5.0dev (2017-05-17 trunk 58600) [x86_64-darwin16]
~~~

----------------------------------------
Feature #12996: Optimize Range#===
https://bugs.ruby-lang.org/issues/12996#change-64873

* Author: ksss (Yuki Kurihara)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
The proposal is that Range#=== optimize by reducing method calls.

## Benchmark

~~~shell
$ cat t.rb
i = 0
while i < 1_000_000
  case i
  when 1..1000
  end
  i += 1
end
~~~

~~~
$ time ./miniruby -e 1
./miniruby -e 1  0.01s user 0.00s system 85% cpu 0.013 total
~~~

### Before

~~~
$ time ./miniruby t.rb
./miniruby t.rb  0.60s user 0.00s system 99% cpu 0.605 total
~~~

### After

~~~
$ time ./miniruby t.rb
./miniruby t.rb  0.41s user 0.00s system 99% cpu 0.420 total
~~~

## Important point

Break compatibility in this case.

https://github.com/ruby/ruby/blob/80045bc2a9e12012d6d16517ea5cb037e67eb2c1/test/ruby/test_range.rb#L333-L355

I don't know how to fix this issue.
But I think, This is a key sentence maybe.
https://github.com/ruby/ruby/blob/8130ee5c9dea6d1323d41271cc01c8dc5d8bcc5d/range.c#L1176

---Files--------------------------------
range-eqq.patch (1.35 KB)
range_eqq2.patch (1.2 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>