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.8 required=3.0 tests=AWL,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 2E2631F66E for ; Mon, 24 Aug 2020 14:34:53 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 9A95A1208FB; Mon, 24 Aug 2020 23:34:13 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id DDF151208FC for ; Mon, 24 Aug 2020 23:34:11 +0900 (JST) Received: by filterdrecv-p3iad2-86945d9569-xwnpr with SMTP id filterdrecv-p3iad2-86945d9569-xwnpr-20-5F43D001-C 2020-08-24 14:34:41.097018403 +0000 UTC m=+333101.028994746 Received: from herokuapp.com (unknown) by geopod-ismtpd-3-3 (SG) with ESMTP id Qo6PP-goSvOi-xjomq0xsg for ; Mon, 24 Aug 2020 14:34:41.032 +0000 (UTC) Date: Mon, 24 Aug 2020 14:34:41 +0000 (UTC) From: gamelinks007@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: 75514 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 17127 X-Redmine-Issue-Author: S_H_ X-Redmine-Sender: S_H_ 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?hkhH+VYi3CHo0H3puLbdQ20XoWHmZIf5UShlDYZVe96KWoE8yLXUikl48HPlJJ?= =?us-ascii?Q?2vfEGtk=2FJlbZyJgWFm0Q5e4VRYN265HP6STkl+F?= =?us-ascii?Q?B5tUZAAPX58XZLmPvqi5GZoMx61iTJpxrzpoUxU?= =?us-ascii?Q?+kHIOkKmy9D7Y2o5h+OsmaBg8f=2FRe77l7BLS7vM?= =?us-ascii?Q?aAOgmft35WmBirIBXsvoZm6xIT4TnJcFKSThpBX?= =?us-ascii?Q?Ll3FClO6if5pqH9cQ=3D?= To: ruby-dev@ruby-lang.org X-ML-Name: ruby-dev X-Mail-Count: 50950 Subject: [ruby-dev:50950] [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 S_H_ (Shun Hiraoka). k0kubun (Takashi Kokubun) wrote in #note-3: > 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. Thanks! ---------------------------------------- Feature #17127: Some TrueClass methods are faster if implemented in Ruby https://bugs.ruby-lang.org/issues/17127#change-87170 * 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/