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=-4.1 required=3.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=ham 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 49A6B1F4B4 for ; Sat, 26 Dec 2020 01:27:57 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id CA77B120AD8; Sat, 26 Dec 2020 10:27:08 +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 EF440120AC7 for ; Sat, 26 Dec 2020 10:27:06 +0900 (JST) Received: by filterdrecv-p3mdw1-7474cd8bfd-mjf6h with SMTP id filterdrecv-p3mdw1-7474cd8bfd-mjf6h-19-5FE69198-5 2020-12-26 01:27:52.094914796 +0000 UTC m=+1304733.628441035 Received: from herokuapp.com (unknown) by ismtpd0142p1mdw1.sendgrid.net (SG) with ESMTP id hrcOUHrbSmub1OwtUHBlAA for ; Sat, 26 Dec 2020 01:27:52.030 +0000 (UTC) Date: Sat, 26 Dec 2020 01:27:52 +0000 (UTC) From: hsbt@ruby-lang.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Redmine-MailingListIntegration-Message-Ids: 77600 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 13368 X-Redmine-Issue-Author: watson1978 X-Redmine-Issue-Assignee: mrkn X-Redmine-Sender: hsbt 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?9+ToIm+BmphpEzrVEr2fqVDpB0VofQNbgfqsVvtPdY2N5oLaAeWcHM3MfECi9h?= =?us-ascii?Q?IF78axm7pJvSMt8JF+i0VH5fd1XOJlO584KLSfQ?= =?us-ascii?Q?PRX4yIAJRDGZRk0Nlv8WEUCKvEbiEFuzZzYO556?= =?us-ascii?Q?jJPAd9DOeVUdKlW=2FegEowWrg46SMHVt4Xe1ujXf?= =?us-ascii?Q?F8G7JVTuYCZZ6QcNttMZcNOTPN4RXwPey+cz+ZH?= =?us-ascii?Q?KJE38=2FQInlUfQlOw8=3D?= To: ruby-dev@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-dev X-Mail-Count: 50983 Subject: [ruby-dev:50983] [Ruby master Feature#13368] Improve performance of Array#sum with float elements 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 #13368 has been updated by hsbt (Hiroshi SHIBATA). Assignee set to mrkn (Kenta Murata) Status changed from Open to Closed https://github.com/ruby/ruby/pull/1555 was merged at https://github.com/ruby/ruby/commit/2d001003e4b3a6c20ead09ed54b6726a7669f457 ---------------------------------------- Feature #13368: Improve performance of Array#sum with float elements https://bugs.ruby-lang.org/issues/13368#change-89526 * Author: watson1978 (Shizuo Fujita) * Status: Closed * Priority: Normal * Assignee: mrkn (Kenta Murata) ---------------------------------------- The declaration of local variable in loop, it will initialize local variable for each run of the loop with clang generated code. So, it shouldn't declare the local variable in heavy loop. Array#sum with float elements will be faster around 30%. ### Before ~~~ user system total real 3.320000 0.010000 3.330000 ( 3.336088) ~~~ ### After ~~~ user system total real 2.590000 0.010000 2.600000 ( 2.602399) ~~~ ### Test code ~~~ require 'benchmark' Benchmark.bmbm do |x| ary = [] 10000.times { ary << Random.rand } x.report do 50000.times do ary.sum end end end ~~~ ### Patch https://github.com/ruby/ruby/pull/1555 -- https://bugs.ruby-lang.org/