ruby-dev (Japanese) list archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-dev:50948] [Ruby master Feature#17127] Some TrueClass methods is faster if implemented in Ruby
@ 2020-08-20 14:03 gamelinks007
  2020-08-21 18:37 ` [ruby-dev:50949] [Ruby master Feature#17127] Some TrueClass methods are " takashikkbn
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: gamelinks007 @ 2020-08-20 14:03 UTC (permalink / raw)
  To: ruby-dev

Issue #17127 has been reported by S_H_ (Shun Hiraoka).

----------------------------------------
Feature #17127: Some TrueClass methods is faster if implemented in Ruby
https://bugs.ruby-lang.org/issues/17127

* Author: S_H_ (Shun Hiraoka)
* Status: Open
* Priority: Normal
----------------------------------------
Some TrueClass methods is 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 theese methods.



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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-11-05  7:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-20 14:03 [ruby-dev:50948] [Ruby master Feature#17127] Some TrueClass methods is faster if implemented in Ruby gamelinks007
2020-08-21 18:37 ` [ruby-dev:50949] [Ruby master Feature#17127] Some TrueClass methods are " takashikkbn
2020-08-24 14:34 ` [ruby-dev:50950] " gamelinks007
2020-08-26  9:05 ` [ruby-dev:50951] " gamelinks007
2020-11-05  7:11 ` [ruby-dev:50969] " gamelinks007

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).