Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sRGq8-00EDxR-FK for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Jul 2024 19:49:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sRGq6-00HHf7-B1 for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Jul 2024 19:49:26 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sRGq5-00HHer-78 for pgsql-hackers@lists.postgresql.org; Tue, 09 Jul 2024 19:49:26 +0000 Received: from fhigh8-smtp.messagingengine.com ([103.168.172.159]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sRGq1-001Fnd-UQ for pgsql-hackers@postgresql.org; Tue, 09 Jul 2024 19:49:24 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 63ECC114032E; Tue, 9 Jul 2024 15:49:20 -0400 (EDT) Received: from imap48 ([10.202.2.98]) by compute6.internal (MEProxy); Tue, 09 Jul 2024 15:49:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=compiler.org; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1720554560; x=1720640960; bh=0ufT1eH9Yo 8g+qcYN7WGtG8PA/2OTUphqv0kZYE4RcI=; b=XcUIUAMUdNkjObj7uW9GqYhDxy u18HTvpXrQ3TTsYgfKUekJ6nylFXWM6HIYGp87zjhbD163EGoQGq8FdjeaOf2ISh F0/cRtzyq96ETw+wERtkm3AxU/oqBjJBAjfLyo+qnlarHCwWEh7DMM9r+46EpHju APlV3irN+I22uKcEtDdFU60lXCyux6+LIr/x8gShkRPbW1Fg3o1jIwMTQjCmEjeP t6+0l/oQcaMjtu2A70zo0o4CWg8CMfTn50JGDqy3Qyqnp1baudScZhJXR76/v3bu V+48y1gSMLoD3pY6gw5AKD/738RXrGwoB1Ot5UXYQGBY//9B5akAjd7mNbYA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1720554560; x=1720640960; bh=0ufT1eH9Yo8g+qcYN7WGtG8PA/2O TUphqv0kZYE4RcI=; b=ORdJPM8WWIjysvx84yg7fA71pjizNIMPGjR4CfAZd9EC VCZpgJncfTeiOXQ8ChqSmkbo8epaOVKBI5DA6gf02/LhoUWUZAyyAXFXwTDbqhSZ MjlS00G5hCJUhyXhFS74dp62nUqFXn/AYKWgGZkpXQjCcCo6hKGE1zdP9Xw4ogZB BBRGbu78eYEOa704oZuFdELOY5+HjEBfslCzJsY7kR0sPLQcqrGBxy6bmvEjVRwj 4iOWXjUlJeU5ejtga7kUQo1N9BCvu++2JurzQ9XyTipssXeYVUY6ZnMPdNXEXrxA ZLBolQ3C613T1o6OwznHup8b3olI6z7seHtVExZmww== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdelgddugedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvfevufgtsehttdertderredtnecuhfhrohhmpedflfho vghlucflrggtohgsshhonhdfuceojhhovghlsegtohhmphhilhgvrhdrohhrgheqnecugg ftrfgrthhtvghrnhephfefudegffdvtdetleeuhfffkeeltddukefhkeekieelleffhfef tdffjefgjeefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homhepjhhovghlsegtohhmphhilhgvrhdrohhrgh X-ME-Proxy: Feedback-ID: ic6394509:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 095E531A0065; Tue, 9 Jul 2024 15:49:18 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-568-g843fbadbe-fm-20240701.003-g843fbadb MIME-Version: 1.0 Message-Id: <7f733f07-8631-4019-96bf-df83b14919bb@app.fastmail.com> In-Reply-To: <252c8b54-3962-4d0a-8479-43f429bd7015@app.fastmail.com> References: <44d2ffca-d560-4919-b85a-4d07060946aa@app.fastmail.com> <87zfr1e1uj.fsf@wibble.ilmari.org> <9ff90ff9-5ac1-4529-b2f4-f93b37734b9c@app.fastmail.com> <81348268-b9fd-4308-bf52-056070aa7c2a@app.fastmail.com> <8e909218-1965-4515-99e3-4bb5b625e004@app.fastmail.com> <0459ded5-6daf-4bf0-9ab0-e1f11ab15ec6@app.fastmail.com> <4e54bf4f-59fe-4c9a-b446-a2b64cbfd584@app.fastmail.com> <27d42b25-f328-4231-9db0-3811dc77c8cf@app.fastmail.com> <33c51978-8ee8-438c-9804-e46c0ca8f3f9@app.fastmail.com> <018dd6e8-8f21-4b3b-8d80-2d128f6d00b4@app.fastmail.com> <32510d71-8c00-4896-9c11-5ea4b3c01ffc@app.fastmail.com> <31b8386d-4bcb-4909-b7da-bbeb9a8ece55@app.fastmail.com> <42d93ebe-fbed-448f-b550-096be9e577db@app.fastmail.com> <58e5e7d2-7ad8-40b4-9b76-a5c3049346e5@app.fastmail.com> <252c8b54-3962-4d0a-8479-43f429bd7015@app.fastmail.com> Date: Tue, 09 Jul 2024 21:48:57 +0200 From: "Joel Jacobson" To: "Dean Rasheed" Cc: =?UTF-8?Q?Dagfinn_Ilmari_Manns=C3=A5ker?= , pgsql-hackers Subject: Re: Optimize numeric multiplication for one and two base-NBASE digit multiplicands. Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Jul 9, 2024, at 16:11, Joel Jacobson wrote: > I added some more ndigits test cases: Ops, please ignore previous benchmark; I had forgot to commit in between the measurements, so they all ran in the same db txn, which caused a lot of noise on few ndigits. New benchmark: > /* > * Intel Core i9-14900K > */ NBASE digits | HEAD rate | patch rate | relative difference --------------+----------------+----------------+--------------------- 1 | 5.0251256e+07 | 5.2631579e+07 | 4.74% 2 | 4.8543689e+07 | 4.9751244e+07 | 2.49% 3 | 4.1493776e+07 | 4.3478261e+07 | 4.78% 4 | 4.1493776e+07 | 4.0816327e+07 | -1.63% 5 | 2.2371365e+07 | 2.3364486e+07 | 4.44% 6 | 2.1008403e+07 | 2.1186441e+07 | 0.85% 7 | 1.7152659e+07 | 1.6233766e+07 | -5.36% 8 | 1.7123288e+07 | 1.8450185e+07 | 7.75% 9 | 1.5290520e+07 | 1.7271157e+07 | 12.95% 10 | 1.3351135e+07 | 1.5384615e+07 | 15.23% 11 | 1.2453300e+07 | 1.4164306e+07 | 13.74% 12 | 1.1655012e+07 | 1.2936611e+07 | 11.00% 13 | 1.0373444e+07 | 1.1904762e+07 | 14.76% 14 | 9.0909091e+06 | 1.0162602e+07 | 11.79% 15 | 7.7519380e+06 | 8.1300813e+06 | 4.88% 16 | 9.0909091e+06 | 9.8039216e+06 | 7.84% 17 | 7.5757576e+06 | 9.0909091e+06 | 20.00% 18 | 7.2463768e+06 | 8.2644628e+06 | 14.05% 19 | 6.6225166e+06 | 7.5757576e+06 | 14.39% 20 | 6.4516129e+06 | 7.0422535e+06 | 9.15% 21 | 6.0606061e+06 | 6.5789474e+06 | 8.55% 22 | 5.7142857e+06 | 6.2500000e+06 | 9.38% 24 | 5.4054054e+06 | 6.0240964e+06 | 11.45% 25 | 5.2356021e+06 | 5.8139535e+06 | 11.05% 26 | 5.0251256e+06 | 5.8139535e+06 | 15.70% 27 | 4.7393365e+06 | 5.7142857e+06 | 20.57% 28 | 4.6082949e+06 | 5.2083333e+06 | 13.02% 29 | 4.3478261e+06 | 4.9504950e+06 | 13.86% 30 | 4.0816327e+06 | 4.6728972e+06 | 14.49% 31 | 3.4843206e+06 | 3.9682540e+06 | 13.89% 32 | 4.0000000e+06 | 4.1666667e+06 | 4.17% 50 | 2.1097046e+06 | 2.8571429e+06 | 35.43% 100 | 680272.11 | 909090.91 | 33.64% 250 | 141643.06 | 174216.03 | 23.00% 2500 | 1626.02 | 2188.18 | 34.57% 15000 | 41.67 | 52.63 | 26.32% (36 rows) > /* > * AMD Ryzen 9 7950X3D > */ NBASE digits | HEAD rate | patch rate | relative difference --------------+----------------+----------------+--------------------- 1 | 3.7037037e+07 | 3.8910506e+07 | 5.06% 2 | 3.5587189e+07 | 3.5971223e+07 | 1.08% 3 | 3.0581040e+07 | 2.9239766e+07 | -4.39% 4 | 2.7322404e+07 | 3.0303030e+07 | 10.91% 5 | 1.8050542e+07 | 1.9011407e+07 | 5.32% 6 | 1.5974441e+07 | 1.6233766e+07 | 1.62% 7 | 1.3106160e+07 | 1.3071895e+07 | -0.26% 8 | 1.2285012e+07 | 1.3106160e+07 | 6.68% 9 | 1.1534025e+07 | 1.2269939e+07 | 6.38% 10 | 1.1135857e+07 | 1.1507480e+07 | 3.34% 11 | 9.7943193e+06 | 1.0976948e+07 | 12.07% 12 | 9.5238095e+06 | 1.0256410e+07 | 7.69% 13 | 8.6206897e+06 | 8.7719298e+06 | 1.75% 14 | 7.3529412e+06 | 8.1967213e+06 | 11.48% 15 | 6.2893082e+06 | 6.7114094e+06 | 6.71% 16 | 7.2463768e+06 | 7.0422535e+06 | -2.82% 17 | 6.2893082e+06 | 7.2463768e+06 | 15.22% 18 | 6.3694268e+06 | 7.4626866e+06 | 17.16% 19 | 5.6818182e+06 | 6.6225166e+06 | 16.56% 20 | 5.2083333e+06 | 6.1728395e+06 | 18.52% 21 | 5.0251256e+06 | 5.7471264e+06 | 14.37% 22 | 4.5248869e+06 | 5.1282051e+06 | 13.33% 24 | 4.9261084e+06 | 5.1020408e+06 | 3.57% 25 | 4.6511628e+06 | 4.9504950e+06 | 6.44% 26 | 4.2553191e+06 | 4.6082949e+06 | 8.29% 27 | 3.9682540e+06 | 4.2918455e+06 | 8.15% 28 | 3.8910506e+06 | 4.1322314e+06 | 6.20% 29 | 3.8167939e+06 | 3.7593985e+06 | -1.50% 30 | 3.5842294e+06 | 3.6101083e+06 | 0.72% 31 | 3.1948882e+06 | 3.1645570e+06 | -0.95% 32 | 3.4722222e+06 | 3.7174721e+06 | 7.06% 50 | 1.6474465e+06 | 2.1691974e+06 | 31.67% 100 | 555555.56 | 653594.77 | 17.65% 250 | 109409.19 | 140449.44 | 28.37% 2500 | 1236.09 | 1555.21 | 25.82% 15000 | 34.48 | 43.48 | 26.09% (36 rows) > /* > * Apple M3 Max > */ NBASE digits | HEAD rate | patch rate | relative difference --------------+----------------+----------------+--------------------- 1 | 4.7169811e+07 | 4.7619048e+07 | 0.95% 2 | 6.0240964e+07 | 5.8479532e+07 | -2.92% 3 | 5.2083333e+07 | 5.3191489e+07 | 2.13% 4 | 4.5871560e+07 | 4.6948357e+07 | 2.35% 5 | 2.2075055e+07 | 2.3529412e+07 | 6.59% 6 | 2.0080321e+07 | 2.1505376e+07 | 7.10% 7 | 1.7301038e+07 | 1.8975332e+07 | 9.68% 8 | 1.6025641e+07 | 1.6556291e+07 | 3.31% 9 | 1.3245033e+07 | 1.3717421e+07 | 3.57% 10 | 1.1709602e+07 | 1.2315271e+07 | 5.17% 11 | 1.0000000e+07 | 1.0989011e+07 | 9.89% 12 | 9.0909091e+06 | 9.7276265e+06 | 7.00% 13 | 8.3333333e+06 | 9.0090090e+06 | 8.11% 14 | 7.6923077e+06 | 8.0645161e+06 | 4.84% 15 | 7.0921986e+06 | 7.5187970e+06 | 6.02% 16 | 6.6666667e+06 | 7.0921986e+06 | 6.38% 17 | 6.2111801e+06 | 6.3694268e+06 | 2.55% 18 | 5.7803468e+06 | 5.9523810e+06 | 2.98% 19 | 5.2910053e+06 | 5.4347826e+06 | 2.72% 20 | 4.7846890e+06 | 5.0505051e+06 | 5.56% 21 | 4.5454545e+06 | 4.6728972e+06 | 2.80% 22 | 4.2372881e+06 | 4.3859649e+06 | 3.51% 24 | 3.7174721e+06 | 3.8759690e+06 | 4.26% 25 | 3.4722222e+06 | 3.6231884e+06 | 4.35% 26 | 3.2894737e+06 | 3.3898305e+06 | 3.05% 27 | 3.0674847e+06 | 3.1847134e+06 | 3.82% 28 | 2.9239766e+06 | 3.0120482e+06 | 3.01% 29 | 2.7548209e+06 | 2.8901734e+06 | 4.91% 30 | 2.6041667e+06 | 2.7322404e+06 | 4.92% 31 | 2.5000000e+06 | 2.5773196e+06 | 3.09% 32 | 4.6082949e+06 | 4.7846890e+06 | 3.83% 50 | 1.7241379e+06 | 2.0703934e+06 | 20.08% 100 | 719424.46 | 869565.22 | 20.87% 250 | 124688.28 | 157977.88 | 26.70% 2500 | 1455.60 | 1811.59 | 24.46% 15000 | 40.00 | 50.00 | 25.00% (36 rows) Regards, Joel