Skip Menu |
 

This queue is for tickets about the Math-BigInt CPAN distribution.

Report information
The Basics
Id: 43924
Status: resolved
Priority: 0/
Queue: Math-BigInt

People
Owner: Nobody in particular
Requestors: emazep [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.89
Fixed in: 1.999701



Subject: Huge slowdown in blog(x) when x begins with 1
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Type: text/plain
Charset: utf8
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 1054
It seems that there is a huge slowdown in blog(x) whenever x is a number beginning with 1. Consider the following script: --- use strict; use warnings; use Benchmark qw(cmpthese); use Math::BigFloat; # $x is a big number beginning with 1 our $x = Math::BigFloat->new( '1234567890' x 20 ); # $x2 = $x * 2 ($x2 begins with 2) our $x2 = $x->copy->bmul(2); cmpthese( -10, { log_2x => sub { $x2->copy->blog }, log_x => sub { $x->copy->blog } }); --- It prints out: Rate log_x log_2x log_x 1.14/s -- -95% log_2x 24.4/s 2038% -- which shows that (in this case) calculating blog(x) takes more than *20 times* longer than calculating blog(2*x) (this ratio tends to diverge when the size of x increases). Whatever the reason, this can easily be avoided at least by naively implementing blog(x) by blog(2*x)-blog(2) when x is a number beginning with 1 (multiplying by 2 a number beginning with 1 always gives a number beginning with a digit != 1). Thank you for your great work, Emanuele Zeppieri
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Charset: utf8
Content-Type: multipart/mixed; boundary="----------=_1236424286-2264-313"
Message-ID: <rt-3.6.HEAD-2264-1236424286-1542.43924-0-0 [...] rt.cpan.org>
X-RT-Original-Encoding: iso-8859-1
Content-Length: 0
Content-Disposition: inline
Content-Type: text/plain
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: iso-8859-1
Content-Length: 0
MIME-Version: 1.0
Subject: perl-V.txt
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Type: multipart/mixed; boundary="----------=_1236424286-2264-312"
Charset: utf8
Content-Length: 0
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: iso-8859-1
Content-Length: 0
Content-Type: text/plain; charset="utf-8"; name="perl-V.txt"
Content-Disposition: inline; filename="perl-V.txt"
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 2758
Download perl-V.txt
text/plain 2.6k
Summary of my perl5 (revision 5 version 10 subversion 0 patch 34065) configuration: Platform: osname=cygwin, osvers=1.5.25(0.15642), archname=cygwin-thread-multi-64int uname='cygwin_nt-5.1 reini 1.5.25(0.15642) 2008-06-12 19:34 i686 cygwin ' config_args='-de -Dmksymlinks -Dusethreads -Dmad=y -Dusedevel' hint=recommended, useposix=true, d_sigaction=define useithreads=define, usemultiplicity=define useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef use64bitint=define, use64bitall=undef, uselongdouble=undef usemymalloc=y, bincompat5005=undef Compiler: cc='gcc', ccflags ='-DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__ -fno-strict-aliasing -pipe -I/usr/local/include', optimize='-O3', cppflags='-DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__ -fno-strict-aliasing -pipe -I/usr/local/include' ccversion='', gccversion='3.4.4 (cygming special, gdc 0.12, using dmd 0.125)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='g++', ldflags =' -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,--stack,8388608 -Wl,--enable-auto-image-base -L/usr/local/lib' libpth=/usr/local/lib /usr/lib /lib libs=-lgdbm -ldb -ldl -lcrypt -lgdbm_compat perllibs=-ldl -lcrypt libc=/usr/lib/libc.a, so=dll, useshrplib=true, libperl=libperl.a gnulibc_version='' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' ' cccdlflags=' ', lddlflags=' --shared -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,--stack,8388608 -Wl,--enable-auto-image-base -L/usr/local/lib' Characteristics of this binary (from libperl): Compile-time options: MULTIPLICITY MYMALLOC PERL_DONT_CREATE_GVSV PERL_IMPLICIT_CONTEXT PERL_MAD PERL_MALLOC_WRAP PERL_USE_SAFE_PUTENV USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES USE_PERLIO USE_REENTRANT_API Locally applied patches: MAINT34065 CYG11 no-bs CYG12 no archlib in otherlibdirs CYG14 Dynaloader CYG15 static-Win32CORE Bug#55162 File::Spec::case_tolerant performance Built under cygwin Compiled at Jun 30 2008 16:05:15 %ENV: CYGWIN="" @INC: /usr/lib/perl5/5.10/i686-cygwin /usr/lib/perl5/5.10 /usr/lib/perl5/site_perl/5.10/i686-cygwin /usr/lib/perl5/site_perl/5.10 /usr/lib/perl5/vendor_perl/5.10/i686-cygwin /usr/lib/perl5/vendor_perl/5.10 /usr/lib/perl5/vendor_perl/5.10 /usr/lib/perl5/site_perl/5.8 /usr/lib/perl5/vendor_perl/5.8 .
MIME-Version: 1.0
X-Spam-Status: No, hits=-1.0 required=8.0 tests=RCVD_IN_DNSWL_LOW
In-Reply-To: <rt-3.6.HEAD-2264-1236424083-916.43924-4-0 [...] rt.cpan.org>
References: <RT-Ticket-43924 [...] rt.cpan.org> <rt-3.6.HEAD-2264-1236424083-916.43924-4-0 [...] rt.cpan.org>
X-Virus-Checked: Checked by ClamAV on 16.mx.develooper.com
X-Pair-Authenticated: 84.63.59.117
Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAMFBMVEUyTo9PgLt6dK1xgaOmqcl6wOuurOKkvs6+wN+v4ffY2/jb3enu7ffy+v77+f/9//zm1tSJAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH1wYNDzo0sYTGuwAAADx0RVh0Q29tbWVudAAoYykgYnkgVGVscyBibG9vZGdhdGUuY29tLiAyMDAzIEFsbCBSaWdodHMgUmVzZXJ2ZWQunDFKTgAAAb5JREFUOMvlk79u2zAQxrl0rwfvgV8hQ16Ag1cPGjS2AYQ8QIAUyBoEgvcMHrwbjDIHiNQ+gHXUXthH7YV0fAJSPdJ/4jbIAwS5QYDuR30k7/skhndKfHrgwsN09j/gvXUYy/4DHBHt+uhOAXlqOqKGGgvQngJLANRhp7eE1B4BL+2qugSoOiR6lfJhdVXGQuqPADf1L6hrmcvbxwYNC+yBrgDK8oeU8qZs+vb1HrWuWeNuKqe3Ohz8cBFRbp6rjbqTcvrEWyPZHXGiXM/VKue+KgAAjebtXcvgRSkGWXY5Oee6uM4L6MMIBKj8Psu+n4lQ45vrc5nPAbEVSvHy7Gwy+ToSowTNSir1qPmLoHSfTbKrbyMxTpb+z2quIEht4x5XuZrNxJd0aXCdFzpIGQRGav6UzMQ4Xfph+1LpwRkGuAVQBT4ks2SB7RAmPQy9INdiD+ui/52k6QIHw/0w4+CHM1Sy7kO6WKIntuwA2MG6ItwsfqKhWHYPiDoI80CM3ehWDAO/cb/SQcV6GyccgY8A2OPg/26+u1xFEK7Fods7cgCcK9NHw+k0iXxgbIjs2+xyBPkr/xZ4PIp/zJ/zL9K+/Fxg8Z/MAAAAAElFTkSuQmCC
Content-Type: multipart/signed; boundary="nextPart11782209.gRVpnmnLf1"; protocol="application/pgp-signature"; micalg=pgp-sha1
Message-ID: <200903071452.51070 [...] bloodgate.com>
Received: from la.mx.develooper.com (x1.develooper.com [63.251.223.170]) by diesel.bestpractical.com (Postfix) with SMTP id 8439319B8177 for <bug-Math-BigInt [...] rt.cpan.org>; Sat, 7 Mar 2009 08:53:20 -0500 (EST)
Received: (qmail 4722 invoked by uid 103); 7 Mar 2009 13:53:19 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 7 Mar 2009 13:53:19 -0000
Received: from relay03.pair.com (HELO relay03.pair.com) (209.68.5.17) by 16.mx.develooper.com (qpsmtpd/0.43rc1) with SMTP; Sat, 07 Mar 2009 05:53:16 -0800
Received: (qmail 19291 invoked from network); 7 Mar 2009 13:52:53 -0000
Received: from 84.63.59.117 (HELO bloodgate.com) (84.63.59.117) by relay03.pair.com with SMTP; 7 Mar 2009 13:52:53 -0000
Delivered-To: cpan-bug+Math-BigInt [...] diesel.bestpractical.com
User-Agent: KMail/1.9.10
Subject: Re: [rt.cpan.org #43924] Huge slowdown in blog(x) when x begins with 1
Return-Path: <nospam-abuse [...] bloodgate.com>
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-Math-BigInt [...] rt.cpan.org
Date: Sat, 7 Mar 2009 14:52:43 +0100
X-Spam-Level: *
To: bug-Math-BigInt [...] rt.cpan.org
Content-Transfer-Encoding: 7bit
From: Tels <nospam-abuse [...] bloodgate.com>
RT-Message-ID: <rt-3.6.HEAD-2264-1236434006-542.43924-0-0 [...] rt.cpan.org>
Content-Length: 0
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 2069
On Saturday 07 March 2009 12:08:03 Emanuele Zeppieri via RT wrote: Show quoted text
> Sat Mar 07 06:08:02 2009: Request 43924 was acted upon. > Transaction: Ticket created by emazep > Queue: Math-BigInt > Subject: Huge slowdown in blog(x) when x begins with 1 > Broken in: 1.89 > Severity: Normal > Owner: Nobody > Requestors: emazep@gmail.com > Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=43924 > > > > It seems that there is a huge slowdown in blog(x) whenever x is a > number beginning with 1. > > Consider the following script: > > --- > > use strict; > use warnings; > > use Benchmark qw(cmpthese); > use Math::BigFloat; > > # $x is a big number beginning with 1 > our $x = Math::BigFloat->new( '1234567890' x 20 ); > # $x2 = $x * 2 ($x2 begins with 2) > our $x2 = $x->copy->bmul(2); > > cmpthese( -10, { > log_2x => sub { $x2->copy->blog }, > log_x => sub { $x->copy->blog } > }); > > --- > > It prints out: > > Rate log_x log_2x > log_x 1.14/s -- -95% > log_2x 24.4/s 2038% -- > > which shows that (in this case) calculating blog(x) takes more than > *20 times* longer than calculating blog(2*x) (this ratio tends to > diverge when the size of x increases). > > Whatever the reason, this can easily be avoided at least by naively > implementing blog(x) by blog(2*x)-blog(2) when x is a number > beginning with 1 (multiplying by 2 a number beginning with 1 always > gives a number beginning with a digit != 1).
I haven't looked (and I currently have almost zero time for Perl, sorry :( but it might be a simple case of the code accidentily using BigIntegers internally when the number begins with 1, by not converting some small number to a scalar or so. Thank you for your report! Tels -- Signed on Sat Mar 7 14:51:51 2009 with key 0x93B84C15. Get one of my photo posters: http://bloodgate.com/posters PGP key on http://bloodgate.com/tels.asc or per email. "Now, admittedly, it's critical software. This is the 'let's go kill people' software." -- Mark A. Welsh III
Content-Description: This is a digitally signed message part.
content-type: application/pgp-signature; name="signature.asc"
Content-Length: 481
Download signature.asc
application/pgp-signature 481b

Message body not shown because it is not plain text.

MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-21735-1341855700-757.43924-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 392
Download (untitled) / with headers
text/plain 392b
Confirmed that this is still an issue: use strict; use warnings; use Benchmark qw(cmpthese); use Math::BigFloat; our $x = Math::BigFloat->new( '1234567890' x 20 ); our $x2 = Math::BigFloat->new( '2234567890' x 20 ); cmpthese( -10, { log_2x => sub { $x2->copy->blog }, log_x => sub { $x->copy->blog } }); Rate log_x log_2x log_x 1.18/s -- -98% log_2x 47.2/s 3914% --
MIME-Version: 1.0
In-Reply-To: <rt-3.8.HEAD-21735-1341855700-757.43924-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-3.8.HEAD-21735-1341855700-757.43924-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.16-19901-1382469582-903.43924-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 934
Download (untitled) / with headers
text/plain 934b
This happens because _log_10 first moves the decimal place over (so XYYYYYY.ZZZ becomes X.YYYYYYZZZ) then we do a comparison of X >= 2 right before the "if $twos != 0" loop. If X >= 2, we divide by two *and round to $scale+4*. So in the case of '2234567890' x 20, we have divided by two with rounding, so we send to _log: '1.11728394511172839451117283945111728394511172839' In the case of '1234567890' x 20, we send: '1.234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789' The former is much faster. Adding the line: $x->bround($scale+4) on line ~1480 of BigFloat.pm, right after the while statements and before the 'if ($twos != 0)' will speed up the first case in the benchmark by about 20x. With that change, the test suite passes. I'm not sure if it is the *right* fix.
From nospam-abuse [...] bloodgate.com Wed Oct 23 13: 56:25 2013
MIME-Version: 1.0
X-Spam-Status: No, score=-5.55 tagged_above=-99.9 required=10 tests=[AWL=-1.350, BAYES_50=0.8, RCVD_IN_DNSWL_HI=-5] autolearn=ham
In-Reply-To: <rt-4.0.16-19901-1382469582-1112.43924-5-0 [...] rt.cpan.org>
X-Spam-Flag: NO
X-RT-Interface: API
References: <RT-Ticket-43924 [...] rt.cpan.org> <rt-3.8.HEAD-21735-1341855700-757.43924-5-0 [...] rt.cpan.org> <rt-4.0.16-19901-1382469582-1112.43924-5-0 [...] rt.cpan.org>
Importance: Normal
X-Virus-Scanned: Debian amavisd-new at bestpractical.com
Message-ID: <0a93dfe89df1cb371f1eee9e4156ed44.squirrel [...] sm.webmail.pair.com>
Reply-To: nospam-abuse [...] bloodgate.com
content-type: text/plain; charset="utf-8"
X-RT-Original-Encoding: utf-8
X-Spam-Score: -5.55
Received: from localhost (localhost [127.0.0.1]) by hipster.bestpractical.com (Postfix) with ESMTP id 4EEB82413B1 for <cpan-bug+Math-BigInt [...] hipster.bestpractical.com>; Wed, 23 Oct 2013 13:56:25 -0400 (EDT)
Received: from hipster.bestpractical.com ([127.0.0.1]) by localhost (hipster.bestpractical.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QybTfXMS6W49 for <cpan-bug+Math-BigInt [...] hipster.bestpractical.com>; Wed, 23 Oct 2013 13:56:23 -0400 (EDT)
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by hipster.bestpractical.com (Postfix) with SMTP id 90B562405C0 for <bug-Math-BigInt [...] rt.cpan.org>; Wed, 23 Oct 2013 13:56:23 -0400 (EDT)
Received: (qmail 14265 invoked by alias); 23 Oct 2013 17:56:23 -0000
Received: from www4.webmail.pair.com (HELO www4.webmail.pair.com) (66.39.3.58) by la.mx.develooper.com (qpsmtpd/0.28) with SMTP; Wed, 23 Oct 2013 10:56:09 -0700
Received: (qmail 51102 invoked by uid 65534); 23 Oct 2013 17:56:02 -0000
Received: from 217.225.46.52 ([217.225.46.52]) (SquirrelMail authenticated user te_123 [...] bloodgate.com) by sm.webmail.pair.com with HTTP; Wed, 23 Oct 2013 13:56:02 -0400
Delivered-To: cpan-bug+Math-BigInt [...] hipster.bestpractical.com
Subject: Re: [rt.cpan.org #43924] Huge slowdown in blog(x) when x begins with 1
User-Agent: SquirrelMail/1.4.22 [SVN]
Return-Path: <nospam-abuse [...] bloodgate.com>
X-Spam-Check-BY: la.mx.develooper.com
X-Original-To: cpan-bug+Math-BigInt [...] hipster.bestpractical.com
X-RT-Mail-Extension: math-bigint
X-Priority: 3 (Normal)
Date: Wed, 23 Oct 2013 13:56:02 -0400
X-Spam-Level:
To: bug-Math-BigInt [...] rt.cpan.org
Content-Transfer-Encoding: 8bit
From: "Tels" <nospam-abuse [...] bloodgate.com>
RT-Message-ID: <rt-4.0.16-26534-1382550986-429.43924-0-0 [...] rt.cpan.org>
Content-Length: 1707
Download (untitled) / with headers
text/plain 1.6k
On Tue, October 22, 2013 3:19 pm, Dana Jacobsen via RT wrote: Show quoted text
> Queue: Math-BigInt > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=43924 > > > This happens because _log_10 first moves the decimal place over (so > XYYYYYY.ZZZ becomes X.YYYYYYZZZ) then we do a comparison of X >= 2 right > before the "if $twos != 0" loop. If X >= 2, we divide by two *and round > to $scale+4*. > > So in the case of '2234567890' x 20, we have divided by two with rounding, > so we send to _log: > '1.11728394511172839451117283945111728394511172839' > > In the case of '1234567890' x 20, we send: > '1.234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789' > > The former is much faster. Adding the line: > > $x->bround($scale+4) > > on line ~1480 of BigFloat.pm, right after the while statements and before > the 'if ($twos != 0)' will speed up the first case in the benchmark by > about 20x. > > With that change, the test suite passes. I'm not sure if it is the > *right* fix.
IIRC the routine is asked to return a precision of scale, so it keeps internally $scale + 4 (to have enough digits to avoid rounding). So rounding the input in both cases is the "right" thing todo, e.g. at least it will have the same possible output inaccuraries in both cases. Not rounding in one path was probably an oversight on my part, and the testsuite wouldn't catch it if the final result is rounded to $scale before output, unless the intermidiate rounding produces errors due to accumulating them. Hope this helps, tels -- http://bloodgate.com/galleries/
MIME-Version: 1.0
X-Spam-Status: No, score=-4.699 tagged_above=-99.9 required=10 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, FROM_OUR_RT=-2, RCVD_IN_DNSWL_LOW=-0.7] autolearn=ham
In-Reply-To: <rt-4.0.16-19901-1382469583-997.43924-6-0 [...] rt.cpan.org>
X-Spam-Flag: NO
X-RT-Interface: API
References: <RT-Ticket-43924 [...] rt.cpan.org> <rt-3.8.HEAD-21735-1341855700-757.43924-6-0 [...] rt.cpan.org> <rt-4.0.16-19901-1382469583-997.43924-6-0 [...] rt.cpan.org>
X-Virus-Scanned: Debian amavisd-new at bestpractical.com
X-Received: by 10.15.22.131 with SMTP id f3mr148367eeu.29.1401870202372; Wed, 04 Jun 2014 01:23:22 -0700 (PDT)
Message-ID: <538ED777.1050902 [...] gmail.com>
content-type: text/plain; charset="utf-8"
X-RT-Original-Encoding: utf-8
X-Spam-Score: -4.699
Authentication-Results: hipster.bestpractical.com (amavisd-new); dkim=pass header.i= [...] gmail.com
Received: from localhost (localhost [127.0.0.1]) by hipster.bestpractical.com (Postfix) with ESMTP id D61D361E008 for <cpan-bug+Math-BigInt [...] hipster.bestpractical.com>; Wed, 4 Jun 2014 04:23:30 -0400 (EDT)
Received: from hipster.bestpractical.com ([127.0.0.1]) by localhost (hipster.bestpractical.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3LkTddEBbCLu for <cpan-bug+Math-BigInt [...] hipster.bestpractical.com>; Wed, 4 Jun 2014 04:23:29 -0400 (EDT)
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by hipster.bestpractical.com (Postfix) with SMTP id A90FA2409BD for <bug-Math-BigInt [...] rt.cpan.org>; Wed, 4 Jun 2014 04:23:29 -0400 (EDT)
Received: (qmail 16692 invoked by alias); 4 Jun 2014 08:23:29 -0000
Received: from mail-wg0-f46.google.com (HELO mail-wg0-f46.google.com) (74.125.82.46) by la.mx.develooper.com (qpsmtpd/0.28) with ESMTP; Wed, 04 Jun 2014 01:23:26 -0700
Received: by mail-wg0-f46.google.com with SMTP id n12so8048333wgh.5 for <bug-Math-BigInt [...] rt.cpan.org>; Wed, 04 Jun 2014 01:23:22 -0700 (PDT)
Received: from [192.168.1.20] (ppp-56-116.24-151.libero.it. [151.24.116.56]) by mx.google.com with ESMTPSA id 44sm4023289eer.35.2014.06.04.01.23.21 for <bug-Math-BigInt [...] rt.cpan.org> (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 04 Jun 2014 01:23:21 -0700 (PDT)
Delivered-To: cpan-bug+Math-BigInt [...] hipster.bestpractical.com
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Icedove/24.5.0
Subject: Re: [rt.cpan.org #43924] Huge slowdown in blog(x) when x begins with 1
Return-Path: <emazep [...] gmail.com>
Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=kh2TqwesHmEhkZq0IiLGJwhLP/6U51EbNhI6KDIfHkc=; b=wh5el0LT7R2hSG5JFI2RBCdqEXQEYLcQfXTczmW1GjbGV9y6UVa0SEsjeqMnA8rJS3 pX/KiBLS/55fvrZ4XfbgbrDRGsHm6/mCFDTV3G9uCs3Dg3IoCAOMhksIl9VrRqZ82mIw Df7bl/n5vd/uVGrn7q4J/KHOhvBH6BiuVGq/CAeODyyhvQJmIf7np0a1TGvqZJMtVX8Q AnREFdC/2ENmlD4a0Z6/eeQXQIreciY1iwTIj1k4mZWRYQCZ7/h9ie2pr7pGLVcYSbaL 43fcEpesa6DO+Gr2BH3mtxcqtthXp0YKMgTlhn4RGCuno4/Nk+ivHX5FGxAkVY1EqNJ8 m9+w==
X-Spam-Check-BY: la.mx.develooper.com
X-Original-To: cpan-bug+Math-BigInt [...] hipster.bestpractical.com
X-RT-Mail-Extension: math-bigint
Date: Wed, 04 Jun 2014 10:23:19 +0200
X-Spam-Level:
To: bug-Math-BigInt [...] rt.cpan.org
Content-Transfer-Encoding: 7bit
From: Emanuele Zeppieri <emazep [...] gmail.com>
RT-Message-ID: <rt-4.0.18-3916-1401870211-1376.43924-0-0 [...] rt.cpan.org>
Content-Length: 1148
Download (untitled) / with headers
text/plain 1.1k
To the maintainer: can we apply this fix please? Thanks! -Emanuele On 2013-10-22 21:19, Dana Jacobsen via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=43924 > > > This happens because _log_10 first moves the decimal place over (so XYYYYYY.ZZZ becomes X.YYYYYYZZZ) then we do a comparison of X >= 2 right before the "if $twos != 0" loop. If X >= 2, we divide by two *and round to $scale+4*. > > So in the case of '2234567890' x 20, we have divided by two with rounding, so we send to _log: > '1.11728394511172839451117283945111728394511172839' > > In the case of '1234567890' x 20, we send: > '1.234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789' > > The former is much faster. Adding the line: > > $x->bround($scale+4) > > on line ~1480 of BigFloat.pm, right after the while statements and before the 'if ($twos != 0)' will speed up the first case in the benchmark by about 20x. > > With that change, the test suite passes. I'm not sure if it is the *right* fix. >
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-3916-1401870211-1376.43924-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <RT-Ticket-43924 [...] rt.cpan.org> <rt-3.8.HEAD-21735-1341855700-757.43924-6-0 [...] rt.cpan.org> <rt-4.0.16-19901-1382469583-997.43924-6-0 [...] rt.cpan.org> <538ED777.1050902 [...] gmail.com> <rt-4.0.18-3916-1401870211-1376.43924-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-2264-1429883392-873.43924-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 66
MIME-Version: 1.0
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-20613-1442315867-737.43924-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 30
Fixed in Math-BigInt-1.999701.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.