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-ASN: AS4713 221.184.0.0/13 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 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 E38731F462 for ; Tue, 18 Jun 2019 08:42:34 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 1CC0C120A7D; Tue, 18 Jun 2019 17:42:29 +0900 (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 CE727120A3D for ; Tue, 18 Jun 2019 17:42:27 +0900 (JST) Received: by filter0098p3las1.sendgrid.net with SMTP id filter0098p3las1-12263-5D08A3F4-39 2019-06-18 08:42:28.878854467 +0000 UTC m=+404095.922734159 Received: from herokuapp.com (unknown [18.213.4.150]) by ismtpd0068p1mdw1.sendgrid.net (SG) with ESMTP id C6Gj6OIORFq7yi93NIynRQ for ; Tue, 18 Jun 2019 08:42:28.767 +0000 (UTC) Date: Tue, 18 Jun 2019 08:42:28 +0000 (UTC) From: janosch84@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 68706 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15929 X-Redmine-Issue-Author: janosch-x X-Redmine-Sender: janosch-x 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?0k5sXJRcmdpWYfOD1oWBjpTENp+mR02klozhrfvpSZJWai841aPqR5C56CxPhr?= =?us-ascii?Q?YVz50h2Vdsgd8eudMPw7nT6kF1wqvvVe1khv8SX?= =?us-ascii?Q?yFCkcbXjSpWQB0OcnM0fqQOlINwPkKwhpNFNkPV?= =?us-ascii?Q?ZKBTCFcCTTiXsoIobufjpYMOcKI7mXlwmN=2FDlJn?= =?us-ascii?Q?58b0iCTBZwvPd1QyASrs5UOgaceVh1zMoKQ=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 93219 Subject: [ruby-core:93219] [Ruby trunk Bug#15929] Array#minmax is much slower than calling both #min and #max X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #15929 has been updated by janosch-x (Janosch M=FCller). jeremyevans0 (Jeremy Evans) wrote: > We cannot use this approach. [...] I see, thanks for the explanation! ---------------------------------------- Bug #15929: Array#minmax is much slower than calling both #min and #max https://bugs.ruby-lang.org/issues/15929#change-78671 * Author: janosch-x (Janosch M=FCller) * Status: Open * Priority: Normal * Assignee: = * Target version: = * ruby -v: 2.7.0dev * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- this is similar to [issue 15807 about Ranges](https://bugs.ruby-lang.org/is= sues/15807) and maybe also to [13917](https://bugs.ruby-lang.org/issues/139= 17) current situation: - calling `Array#minmax` incurs a performance penalty of almost 50% compare= d to calling both `#min` and `#max` ```ruby require 'benchmark/ips' arr =3D (1..1000).map { rand } Benchmark.ips do |x| x.report('min, max') { [arr.min, arr.max] } x.report('minmax') { arr.minmax } end ``` ``` min, max 53.832k (=B1 1.8%) i/s - 270.861k in 5.033263s minmax 30.093k (=B1 1.2%) i/s - 151.980k in 5.051078s ``` background: - `#minmax` is included via `Enumerable` - `Enumerable#minmax` does not call array's optimized `#min` and `#max` imp= lementations possible solutions: - a) change `Enumerable#minmax` and let it `rb_funcall` `min` and `max` as = suggested [here](https://bugs.ruby-lang.org/issues/15807#note-7) (will also= fix 15807) - b) implement minmax in array.c to call `rb_ary_min` and `rb_ary_max` ---Files-------------------------------- array-minmax.patch (2.65 KB) -- = https://bugs.ruby-lang.org/ Unsubscribe: