XmacsLabs / lolly

lolly: A user-friendly C++ library
https://xmacslabs.github.io/lolly/
GNU General Public License v3.0
10 stars 6 forks source link

[8_11] boost performance of api converting number to hexadecimal string #329

Closed jingkaimori closed 4 months ago

jingkaimori commented 4 months ago

Performance

to_hex faster 50%, as_hexadecimal faster 82%!!!

Before

complexityN ns/op op/s err% total benchmark
1 3.03 329,610,514.51 2.3% 0.02 convert hexadecimal string to int
1 12.77 78,320,857.02 1.9% 0.06 convert signed int to hexadecimal string
1 13.15 76,026,752.24 1.1% 0.06 convert unsigned int to hexadecimal string
2 3.91 255,599,303.35 4.7% 0.02 convert hexadecimal string to int
2 12.69 78,811,782.13 1.0% 0.06 convert signed int to hexadecimal string
2 47.51 21,049,513.78 2.8% 0.23 convert unsigned int to hexadecimal string
3 4.85 206,384,036.36 1.6% 0.02 convert hexadecimal string to int
3 12.81 78,044,226.04 0.7% 0.06 convert signed int to hexadecimal string
3 74.44 13,434,353.45 0.7% 0.36 convert unsigned int to hexadecimal string
4 5.88 170,029,870.91 2.3% 0.03 convert hexadecimal string to int
4 48.58 20,584,946.78 3.1% 0.24 convert signed int to hexadecimal string
4 108.33 9,231,414.46 0.5% 0.52 convert unsigned int to hexadecimal string
5 6.70 149,337,147.16 0.5% 0.03 convert hexadecimal string to int
5 48.16 20,763,956.26 1.3% 0.23 convert signed int to hexadecimal string
5 148.89 6,716,357.71 0.2% 0.72 convert unsigned int to hexadecimal string

After

complexityN ns/op op/s err% total benchmark
1 2.95 339,258,986.45 0.8% 0.02 convert hexadecimal string to int
1 17.74 56,374,077.33 1.5% 0.08 convert signed int to hexadecimal string
1 14.38 69,547,781.82 0.9% 0.07 convert unsigned int to hexadecimal string
2 3.94 253,905,312.41 3.4% 0.02 convert hexadecimal string to int
2 17.42 57,406,505.14 1.2% 0.08 convert signed int to hexadecimal string
2 15.57 64,211,588.80 0.6% 0.08 convert unsigned int to hexadecimal string
3 5.76 173,703,719.01 2.6% 0.03 convert hexadecimal string to int
3 17.49 57,190,688.69 1.1% 0.09 convert signed int to hexadecimal string
3 17.21 58,097,326.85 1.3% 0.08 convert unsigned int to hexadecimal string
4 5.89 169,673,236.32 2.5% 0.03 convert hexadecimal string to int
4 21.83 45,811,805.23 1.0% 0.11 convert signed int to hexadecimal string
4 19.27 51,898,451.76 1.4% 0.09 convert unsigned int to hexadecimal string
5 6.73 148,631,690.89 1.9% 0.03 convert hexadecimal string to int
5 22.18 45,085,309.87 1.1% 0.11 convert signed int to hexadecimal string
5 22.65 44,143,155.21 0.4% 0.11 convert unsigned int to hexadecimal string