\timing
SELECT setseed(0.12345);
CREATE TABLE bench_mul_var_var1ndigits_1 (var1 numeric, var2 numeric);
INSERT INTO bench_mul_var_var1ndigits_1 (var1, var2)
SELECT random(0::numeric,9999::numeric), random(10000000::numeric,1e32::numeric) FROM generate_series(1,1e8);
CREATE TABLE bench_mul_var_var1ndigits_2 (var1 numeric, var2 numeric);
INSERT INTO bench_mul_var_var1ndigits_2 (var1, var2)
SELECT random(10000000::numeric,99999999::numeric), random(100000000000::numeric,1e32::numeric) FROM generate_series(1,1e8);
CREATE TABLE bench_mul_var_var1ndigits_3 (var1 numeric, var2 numeric);
INSERT INTO bench_mul_var_var1ndigits_3 (var1, var2)
SELECT random(100000000000::numeric,999999999999::numeric), random(1000000000000000::numeric,1e32::numeric) FROM generate_series(1,1e8);

/*
 * Apple M3 Max
 */

--
-- var1ndigits=1
--

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_1; -- HEAD
Time: 3090.147 ms (00:03.090)
Time: 3095.153 ms (00:03.095)
Time: 3096.725 ms (00:03.097)
Time: 3070.083 ms (00:03.070)
Time: 3081.267 ms (00:03.081)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_1; -- v4-optimize-numeric-mul_var-small-var1-arbitrary-var2.patch
Time: 2883.311 ms (00:02.883)
Time: 2882.971 ms (00:02.883)
Time: 2884.639 ms (00:02.885)
Time: 2884.728 ms (00:02.885)
Time: 2887.346 ms (00:02.887)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_1; -- v5-add-mul_var_int.patch
Time: 2859.045 ms (00:02.859)
Time: 2854.941 ms (00:02.855)
Time: 2851.976 ms (00:02.852)
Time: 2863.930 ms (00:02.864)
Time: 2864.494 ms (00:02.864)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_1; -- v5-optimize-numeric-mul_var-small-var1-arbitrary-var2.patch
Time: 2869.741 ms (00:02.870)
Time: 2870.023 ms (00:02.870)
Time: 2870.653 ms (00:02.871)
Time: 2869.711 ms (00:02.870)
Time: 2878.178 ms (00:02.878)

--
-- var1ndigits=2
--

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_2; -- HEAD
Time: 3397.181 ms (00:03.397)
Time: 3371.557 ms (00:03.372)
Time: 3356.081 ms (00:03.356)
Time: 3371.946 ms (00:03.372)
Time: 3385.859 ms (00:03.386)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_2; -- v4-optimize-numeric-mul_var-small-var1-arbitrary-var2.patch
Time: 3084.038 ms (00:03.084)
Time: 3082.308 ms (00:03.082)
Time: 3089.160 ms (00:03.089)
Time: 3083.793 ms (00:03.084)
Time: 3081.382 ms (00:03.081)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_2; -- v5-add-mul_var_int.patch
Time: 2782.388 ms (00:02.782)
Time: 2780.564 ms (00:02.781)
Time: 2781.664 ms (00:02.782)
Time: 2776.481 ms (00:02.776)
Time: 2781.443 ms (00:02.781)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_2; -- v5-optimize-numeric-mul_var-small-var1-arbitrary-var2.patch
Time: 3074.596 ms (00:03.075)
Time: 3073.305 ms (00:03.073)
Time: 3078.297 ms (00:03.078)
Time: 3084.720 ms (00:03.085)
Time: 3076.612 ms (00:03.077)

--
-- var1ndigits=3
--

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_3; -- HEAD
Time: 3500.698 ms (00:03.501)
Time: 3490.170 ms (00:03.490)
Time: 3481.300 ms (00:03.481)
Time: 3486.962 ms (00:03.487)
Time: 3473.165 ms (00:03.473)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_3; -- v4-optimize-numeric-mul_var-small-var1-arbitrary-var2.patch
Time: 3196.107 ms (00:03.196)
Time: 3203.074 ms (00:03.203)
Time: 3215.363 ms (00:03.215)
Time: 3204.599 ms (00:03.205)
Time: 3203.819 ms (00:03.204)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_3; -- v5-add-mul_var_int.patch
Time: 3505.878 ms (00:03.506)
Time: 3544.366 ms (00:03.544)
Time: 3521.562 ms (00:03.522)
Time: 3510.695 ms (00:03.511)
Time: 3523.758 ms (00:03.524)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_3; -- v5-optimize-numeric-mul_var-small-var1-arbitrary-var2.patch
Time: 3203.702 ms (00:03.204)
Time: 3206.802 ms (00:03.207)
Time: 3208.966 ms (00:03.209)
Time: 3198.790 ms (00:03.199)
Time: 3202.307 ms (00:03.202)

/*
 * Intel Core i9-14900K
 */

--
-- var1ndigits=1
--

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_1; -- HEAD
Time: 3294.044 ms (00:03.294)
Time: 3296.176 ms (00:03.296)
Time: 3263.968 ms (00:03.264)
Time: 3262.892 ms (00:03.263)
Time: 3263.531 ms (00:03.264)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_1; -- v4-optimize-numeric-mul_var-small-var1-arbitrary-var2.patch
Time: 3125.577 ms (00:03.126)
Time: 3126.274 ms (00:03.126)
Time: 3122.623 ms (00:03.123)
Time: 3123.057 ms (00:03.123)
Time: 3124.143 ms (00:03.124)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_1; -- v5-add-mul_var_int.patch
Time: 3056.697 ms (00:03.057)
Time: 3053.200 ms (00:03.053)
Time: 3053.484 ms (00:03.053)
Time: 3053.548 ms (00:03.054)
Time: 3052.770 ms (00:03.053)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_1; -- v5-optimize-numeric-mul_var-small-var1-arbitrary-var2.patch
Time: 3076.845 ms (00:03.077)
Time: 3078.734 ms (00:03.079)
Time: 3078.344 ms (00:03.078)
Time: 3079.325 ms (00:03.079)
Time: 3077.803 ms (00:03.078)

--
-- var1ndigits=2
--

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_2; -- HEAD
Time: 3398.412 ms (00:03.398)
Time: 3380.465 ms (00:03.380)
Time: 3349.829 ms (00:03.350)
Time: 3351.368 ms (00:03.351)
Time: 3346.712 ms (00:03.347)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_2; -- v4-optimize-numeric-mul_var-small-var1-arbitrary-var2.patch
Time: 3180.399 ms (00:03.180)
Time: 3179.782 ms (00:03.180)
Time: 3181.158 ms (00:03.181)
Time: 3180.896 ms (00:03.181)
Time: 3184.998 ms (00:03.185)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_2; -- v5-add-mul_var_int.patch
Time: 3116.356 ms (00:03.116)
Time: 3111.412 ms (00:03.111)
Time: 3116.011 ms (00:03.116)
Time: 3117.422 ms (00:03.117)
Time: 3118.254 ms (00:03.118)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_2; -- v5-optimize-numeric-mul_var-small-var1-arbitrary-var2.patch
Time: 3189.580 ms (00:03.190)
Time: 3188.140 ms (00:03.188)
Time: 3187.830 ms (00:03.188)
Time: 3189.053 ms (00:03.189)
Time: 3189.717 ms (00:03.190)

--
-- var1ndigits=3
--

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_3; -- HEAD
Time: 4171.285 ms (00:04.171)
Time: 4162.330 ms (00:04.162)
Time: 4142.480 ms (00:04.142)
Time: 4137.238 ms (00:04.137)
Time: 4137.180 ms (00:04.137)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_3; -- v4-optimize-numeric-mul_var-small-var1-arbitrary-var2.patch
Time: 3983.753 ms (00:03.984)
Time: 3983.630 ms (00:03.984)
Time: 3983.684 ms (00:03.984)
Time: 3992.266 ms (00:03.992)
Time: 3984.959 ms (00:03.985)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_3; -- v5-add-mul_var_int.patch
Time: 4159.903 ms (00:04.160)
Time: 4155.236 ms (00:04.155)
Time: 4156.482 ms (00:04.156)
Time: 4154.075 ms (00:04.154)
Time: 4152.739 ms (00:04.153)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_3; -- v5-optimize-numeric-mul_var-small-var1-arbitrary-var2.patch
Time: 3982.057 ms (00:03.982)
Time: 3983.134 ms (00:03.983)
Time: 3984.192 ms (00:03.984)
Time: 3982.792 ms (00:03.983)
Time: 3980.789 ms (00:03.981)

/*
 * AMD Ryzen 9 7950X3D
 */

--
-- var1ndigits=1
--

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_1; -- HEAD
Time: 3306.653 ms (00:03.307)
Time: 3307.260 ms (00:03.307)
Time: 3268.231 ms (00:03.268)
Time: 3276.653 ms (00:03.277)
Time: 3267.375 ms (00:03.267)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_1; -- v4-optimize-numeric-mul_var-small-var1-arbitrary-var2.patch
Time: 2954.318 ms (00:02.954)
Time: 2961.550 ms (00:02.962)
Time: 2963.000 ms (00:02.963)
Time: 2958.896 ms (00:02.959)
Time: 2957.998 ms (00:02.958)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_1; -- v5-add-mul_var_int.patch
Time: 3080.628 ms (00:03.081)
Time: 3064.396 ms (00:03.064)
Time: 3073.567 ms (00:03.074)
Time: 3074.281 ms (00:03.074)
Time: 3072.741 ms (00:03.073)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_1; -- v5-optimize-numeric-mul_var-small-var1-arbitrary-var2.patch
Time: 2932.485 ms (00:02.932)
Time: 2931.049 ms (00:02.931)
Time: 2932.589 ms (00:02.933)
Time: 2927.167 ms (00:02.927)
Time: 2932.993 ms (00:02.933)

--
-- var1ndigits=2
--

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_2; -- HEAD
Time: 3505.663 ms (00:03.506)
Time: 3510.422 ms (00:03.510)
Time: 3470.290 ms (00:03.470)
Time: 3490.446 ms (00:03.490)
Time: 3470.264 ms (00:03.470)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_2; -- v4-optimize-numeric-mul_var-small-var1-arbitrary-var2.patch
Time: 3166.622 ms (00:03.167)
Time: 3162.453 ms (00:03.162)
Time: 3168.570 ms (00:03.169)
Time: 3173.971 ms (00:03.174)
Time: 3170.914 ms (00:03.171)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_2; -- v5-add-mul_var_int.patch
Time: 3135.849 ms (00:03.136)
Time: 3131.497 ms (00:03.131)
Time: 3138.993 ms (00:03.139)
Time: 3135.383 ms (00:03.135)
Time: 3143.074 ms (00:03.143)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_2; -- v5-optimize-numeric-mul_var-small-var1-arbitrary-var2.patch
Time: 3075.388 ms (00:03.075)
Time: 3078.407 ms (00:03.078)
Time: 3075.033 ms (00:03.075)
Time: 3078.055 ms (00:03.078)
Time: 3075.422 ms (00:03.075)

--
-- var1ndigits=3
--

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_3; -- HEAD
Time: 3809.949 ms (00:03.810)
Time: 3824.012 ms (00:03.824)
Time: 3782.624 ms (00:03.783)
Time: 3783.997 ms (00:03.784)
Time: 3761.864 ms (00:03.762)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_3; -- v4-optimize-numeric-mul_var-small-var1-arbitrary-var2.patch
Time: 3459.177 ms (00:03.459)
Time: 3474.086 ms (00:03.474)
Time: 3456.303 ms (00:03.456)
Time: 3475.646 ms (00:03.476)
Time: 3450.919 ms (00:03.451)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_3; -- v5-add-mul_var_int.patch
Time: 3882.610 ms (00:03.883)
Time: 3885.023 ms (00:03.885)
Time: 3884.721 ms (00:03.885)
Time: 3894.463 ms (00:03.894)
Time: 3878.118 ms (00:03.878)

SELECT SUM(var1*var2) FROM bench_mul_var_var1ndigits_3; -- v5-optimize-numeric-mul_var-small-var1-arbitrary-var2.patch
Time: 3302.385 ms (00:03.302)
Time: 3320.810 ms (00:03.321)
Time: 3306.740 ms (00:03.307)
Time: 3307.842 ms (00:03.308)
Time: 3302.253 ms (00:03.302)
