Re: Optimize numeric multiplication for one and two base-NBASE digit multiplicands.
От | Dean Rasheed |
---|---|
Тема | Re: Optimize numeric multiplication for one and two base-NBASE digit multiplicands. |
Дата | |
Msg-id | CAEZATCV2qPTGo2Fd8xDs06Q7iU5aorgSa9+Fw9zkuQv1y15rcw@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Optimize numeric multiplication for one and two base-NBASE digit multiplicands. ("Joel Jacobson" <joel@compiler.org>) |
Ответы |
Re: Optimize numeric multiplication for one and two base-NBASE digit multiplicands.
Re: Optimize numeric multiplication for one and two base-NBASE digit multiplicands. |
Список | pgsql-hackers |
On Mon, 1 Jul 2024 at 20:56, Joel Jacobson <joel@compiler.org> wrote: > > Below is a more realistic benchmark > > CREATE TABLE bench_mul_var (num1 numeric, num2 numeric); > > INSERT INTO bench_mul_var (num1, num2) > SELECT random(0::numeric,1e8::numeric), random(0::numeric,1e8::numeric) FROM generate_series(1,1e8); > > SELECT SUM(num1*num2) FROM bench_mul_var; I had a play with this, and came up with a slightly different way of doing it that works for var2 of any size, as long as var1 is just 1 or 2 digits. Repeating your benchmark where both numbers have up to 2 NBASE-digits, this new approach was slightly faster: SELECT SUM(num1*num2) FROM bench_mul_var; -- HEAD Time: 4762.990 ms (00:04.763) Time: 4332.166 ms (00:04.332) Time: 4276.211 ms (00:04.276) Time: 4247.321 ms (00:04.247) Time: 4166.738 ms (00:04.167) SELECT SUM(num1*num2) FROM bench_mul_var; -- v2 patch Time: 4398.812 ms (00:04.399) Time: 3672.668 ms (00:03.673) Time: 3650.227 ms (00:03.650) Time: 3611.420 ms (00:03.611) Time: 3534.218 ms (00:03.534) SELECT SUM(num1*num2) FROM bench_mul_var; -- this patch Time: 3350.596 ms (00:03.351) Time: 3336.224 ms (00:03.336) Time: 3335.599 ms (00:03.336) Time: 3336.990 ms (00:03.337) Time: 3351.453 ms (00:03.351) (This was on an older Intel Core i9-9900K, so I'm not sure why all the timings are faster. What compiler settings are you using?) The approach taken in this patch only uses 32-bit integers, so in theory it could be extended to work for var1ndigits = 3, 4, or even more, but the code would get increasingly complex, and I ran out of steam at 2 digits. It might be worth trying though. Regards, Dean
Вложения
В списке pgsql-hackers по дате отправления: