ruby-dev (Japanese) list archive (unofficial mirror)
 help / color / mirror / Atom feed
From: gamelinks007@gmail.com
To: ruby-dev@ruby-lang.org
Subject: [ruby-dev:50969] [Ruby master Feature#17127] Some TrueClass methods are faster if implemented in Ruby
Date: Thu, 05 Nov 2020 07:11:53 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-88358.20201105071151.35524@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-17127.20200820140354.35524@ruby-lang.org>

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


recreate PR for marge `.rb` files

https://github.com/ruby/ruby/pull/3737

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

* 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/

      parent reply	other threads:[~2020-11-05  7:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-20 14:03 [ruby-dev:50948] [Ruby master Feature#17127] Some TrueClass methods is " 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 ` gamelinks007 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-88358.20201105071151.35524@ruby-lang.org \
    --to=gamelinks007@gmail.com \
    --cc=ruby-dev@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).