From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-2.6 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=no autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id B94541F66E for ; Fri, 21 Aug 2020 18:37:33 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 82C0C120AC0; Sat, 22 Aug 2020 03:36:59 +0900 (JST) X-Greylist: delayed 102811 seconds by postgrey-1.34 at neon; Sat, 22 Aug 2020 03:36:57 JST Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 8E8BA120ABC for ; Sat, 22 Aug 2020 03:36:57 +0900 (JST) Received: by filterdrecv-p3las1-7c6d97d9cb-z4j2v with SMTP id filterdrecv-p3las1-7c6d97d9cb-z4j2v-20-5F401466-14 2020-08-21 18:37:26.347618953 +0000 UTC m=+88451.417712144 Received: from herokuapp.com (unknown) by ismtpd0049p1mdw1.sendgrid.net (SG) with ESMTP id AxZl7HN6SBSpG5GHA2_ITg for ; Fri, 21 Aug 2020 18:37:26.174 +0000 (UTC) Date: Fri, 21 Aug 2020 18:37:26 +0000 (UTC) From: takashikkbn@gmail.com Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Redmine-MailingListIntegration-Message-Ids: 75498 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 17127 X-Redmine-Issue-Author: S_H_ X-Redmine-Sender: k0kubun X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?9bN4wU0cxWeLAEOz6NELGbwCNAokUg6cnjH8nvx=2Fqgbp+eLnjWJbM6+3iFVkCT?= =?us-ascii?Q?fGnewsJeoSga6V7eDopG1ws9JIPuVPGpHN8GTyp?= =?us-ascii?Q?hg2lvCTCtPG5GDuR8dd+ngP6hRbIrW60XqSFegS?= =?us-ascii?Q?l04LKgvxgrBR8yV1sjfFNfv18++3dft6Wo89knF?= =?us-ascii?Q?nHNupP9MHVtZbA=2FFKTOLRth7DWBUz+2rcxksuvz?= =?us-ascii?Q?v3GhcFq9lIZlC=2FMrI=3D?= To: ruby-dev@ruby-lang.org X-ML-Name: ruby-dev X-Mail-Count: 50949 Subject: [ruby-dev:50949] [Ruby master Feature#17127] Some TrueClass methods are faster if implemented in Ruby X-BeenThere: ruby-dev@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: "Ruby developers \(Japanese\)" List-Id: "Ruby developers \(Japanese\)" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: ruby-dev-bounces@ruby-lang.org Sender: "ruby-dev" Issue #17127 has been updated by k0kubun (Takashi Kokubun). off topic: If you write an entire ticket in English, I think you should post your ticket to ruby-core to attract more audiences instead of ruby-dev, which has been for tickets written in Japanese. ---------------------------------------- Feature #17127: Some TrueClass methods are faster if implemented in Ruby https://bugs.ruby-lang.org/issues/17127#change-87153 * 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/