ruby-dev (Japanese) list archive (unofficial mirror)
 help / color / mirror / Atom feed
From: hsbt@ruby-lang.org
To: ruby-dev@ruby-lang.org
Subject: [ruby-dev:50983] [Ruby master Feature#13368] Improve performance of Array#sum with float elements
Date: Sat, 26 Dec 2020 01:27:52 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-89526.20201226012751.12374@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-13368.20170327035053.12374@ruby-lang.org>

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/

           reply	other threads:[~2020-12-26  1:27 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <redmine.issue-13368.20170327035053.12374@ruby-lang.org>]

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-89526.20201226012751.12374@ruby-lang.org \
    --to=hsbt@ruby-lang.org \
    --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).