In the course of trying to understand the x-only ECDH benchmark results in the silent payments PR (https://github.com/bitcoin-core/secp256k1/pull/1519#discussion_r2006144436), I noticed that we don’t have a benchmark yet for ecmult_const_xonly
, so I added one.
Results on my machine:
0$ ./build/bin/bench_ecmult
1Benchmark , Min(us) , Avg(us) , Max(us)
2
3ecmult_gen , 12.3 , 12.6 , 13.2
4ecmult_const , 27.2 , 28.6 , 30.9
5ecmult_const_xonly , 29.3 , 30.4 , 32.6
6
7...
I was a bit surprised to see that the x-only variant is slower than the regular ecmult_const function, but on the other hand the former allows to skip pubkey deserialization (i.e. determining y with a square root calculation, which is rather expensive), so that has to be taken account for a fair comparison in use-cases like ECDH (see also benchmark commit in #1198). Having an isolated ecmult benchmark for it still seems to make sense, imho. Note that the teardown function is a bit hacky; since we don’t have the parity of the x-only point multiplication results, the full point multiplication ones are calculated and the x coordinates are compared, and bench_ecmult_teardown_helper
isn’t used.