From: gamelinks007@... Date: 2020-08-26T09:05:28+00:00 Subject: [ruby-dev:50951] [Ruby master Feature#17127] Some TrueClass methods are faster if implemented in Ruby Issue #17127 has been updated by S_H_ (Shun Hiraoka). these method able to speeding up implemented by Ruby code. - `TrueClass#^` - `TrueClass#&` benchmark: ```yaml benchmark: to_s: | true.to_s inspect: | true.inspect or: | true | false xor: | true ^ false and: | true & false loop_count: 1000000 ``` result: ```bash sh@MyComputer:~/rubydev/build$ make benchmark/trueclass.yml -e COMPARE_RUBY=~/.rbenv/shims/ruby -e BENCH_RUBY=../install/bin/ruby # Iteration per second (i/s) | |compare-ruby|built-ruby| |:--------|-----------:|---------:| |to_s | 70.669M| 93.297M| | | -| 1.32x| |inspect | 68.119M| 95.079M| | | -| 1.40x| |or | 56.598M| 62.115M| | | -| 1.10x| |xor | 59.137M| 70.666M| | | -| 1.19x| |and | 41.956M| 46.382M| | | -| 1.11x| ``` `COMPARE_RUBY` is `ruby 2.8.0dev (2020-08-20T04:24:55Z master 6509652c13) [x86_64-linux]`. `BENCH_RUBY` is patched ruby. ---------------------------------------- Feature #17127: Some TrueClass methods are faster if implemented in Ruby https://bugs.ruby-lang.org/issues/17127#change-87195 * Author: S_H_ (Shun Hiraoka) * Status: Open * Priority: Normal ---------------------------------------- Some TrueClass methods are faster if implemented in Ruby code. like this. ```ruby class TrueClass def to_s "true".freeze end alias_method :inspect, :to_s def |(bool) true end end ``` benchmark file: ```yaml benchmark: to_s: | true.to_s inspect: | true.inspect or: | true | false loop_count: 1000000 ``` benchmark result: ```bash sh@MyComputer:~/rubydev/build$ make benchmark/trueclass.yml -e COMPARE_RUBY=~/.rbenv/shims/ruby -e BENCH_RUBY=../install/bin/ruby # Iteration per second (i/s) | |compare-ruby|built-ruby| |:--------|-----------:|---------:| |to_s | 66.001M| 91.927M| | | -| 1.39x| |inspect | 70.464M| 97.220M| | | -| 1.38x| |or | 61.434M| 86.484M| | | -| 1.41x| ``` `COMPARE_RUBY` is `ruby 2.8.0dev (2020-08-20T04:24:55Z master 6509652c13) [x86_64-linux]`. `BENCH_RUBY` is ahead of `ruby 2.8.0dev (2020-08-20T04:24:55Z master 6509652c13) [x86_64-linux]`. Probably, inline method cache was able to speed up these methods. pull request: https://github.com/ruby/ruby/pull/3435 -- https://bugs.ruby-lang.org/