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

[9_4] use union instead of strange static_cast #284

Closed jingkaimori closed 7 months ago

da-liii commented 7 months ago

改成union有什么具体的好处么?除了纯粹的代码重构?

jingkaimori commented 7 months ago

@darcy-shen 给url的构造提升了一点性能:

Before

ns/op op/s err% total benchmark
5,910.40 169,193.15 4.7% 0.01 url construct 8
4,576.62 218,501.70 0.2% 0.01 url descends equal
6,551.03 152,647.65 3.7% 0.01 url descends concat 2
16,606.90 60,215.95 1.6% 0.01 url descends concat 8

After

ns/op op/s err% total benchmark
5,685.55 175,884.51 0.8% 0.01 url construct 8
4,501.29 222,158.66 4.6% 0.01 url descends equal
6,548.65 152,703.26 4.6% 0.01 url descends concat 2
16,521.43 60,527.45 4.3% 0.01 url descends concat 8

别的提升体现不出来,因为很多功能的测试都没有涵盖到STRING标签的树节点能否有子节点

jingkaimori commented 7 months ago

Before

complexityN ns/op op/s err% total benchmark
1 87.65 11,409,176.54 0.2% 0.21 construct atomic tree
1 485.33 2,060,441.77 0.6% 1.17 construct compound tree of depth from argument
1 510.27 1,959,754.37 0.6% 1.23 construct compound tree from array
1 758.74 1,317,974.01 0.6% 1.82 construct compound tree of given depth
2 1,132.45 883,044.27 0.3% 2.71 construct compound tree of given depth
3 1,440.51 694,198.03 0.5% 3.44 construct compound tree of given depth
4 1,741.73 574,143.44 0.4% 4.15 construct compound tree of given depth
5 2,044.63 489,085.42 0.8% 4.88 construct compound tree of given depth
1 7.06 141,596,076.39 0.4% 0.02 type of tree
2 7.13 140,168,861.65 2.0% 0.02 type of tree
3 7.10 140,800,335.90 0.3% 0.02 type of tree
4 7.24 138,193,748.81 1.6% 0.02 type of tree
5 6.73 148,611,899.85 3.3% 0.02 type of tree
1 11.00 90,947,829.86 2.0% 0.03 size of tree
2 11.20 89,266,083.46 1.9% 0.03 size of tree
3 10.98 91,066,513.76 1.7% 0.03 size of tree
4 11.13 89,863,538.92 4.0% 0.03 size of tree
5 10.84 92,278,175.35 2.6% 0.03 size of tree
1 9.35 106,966,018.21 3.0% 0.02 immutable index of tree
2 9.56 104,551,842.95 2.1% 0.02 immutable index of tree
3 9.46 105,681,178.15 2.4% 0.03 immutable index of tree
4 9.59 104,308,413.12 1.8% 0.02 immutable index of tree
5 9.46 105,661,628.22 0.6% 0.02 immutable index of tree
1 126.08 7,931,695.54 0.2% 0.30 mutable index of tree
2 126.42 7,909,896.98 0.2% 0.30 mutable index of tree
3 126.47 7,906,751.03 0.4% 0.30 mutable index of tree
4 125.88 7,944,076.77 0.1% 0.30 mutable index of tree
5 127.65 7,833,959.51 0.9% 0.31 mutable index of tree
1 1,024.10 976,464.64 0.5% 2.45 copy tree
2 1,020.08 980,315.75 0.4% 2.44 copy tree
3 1,020.08 980,314.64 1.0% 2.41 copy tree
4 1,021.74 978,726.77 1.2% 2.41 copy tree
5 1,029.78 971,076.98 0.2% 2.46 copy tree
1 408.35 2,448,875.16 0.4% 0.98 equality of tree
2 410.07 2,438,614.30 0.3% 0.98 equality of tree
3 409.97 2,439,202.39 0.3% 0.98 equality of tree
4 411.24 2,431,650.77 0.5% 0.99 equality of tree
5 411.54 2,429,912.22 0.6% 0.99 equality of tree

After

complexityN ns/op op/s err% total benchmark
1 83.63 11,956,977.75 0.2% 0.20 construct atomic tree
1 471.90 2,119,114.03 0.5% 1.13 construct compound tree of depth from argument
1 473.76 2,110,778.14 0.2% 1.13 construct compound tree from array
1 700.86 1,426,826.87 0.4% 1.68 construct compound tree of given depth
2 1,057.22 945,872.47 0.2% 2.53 construct compound tree of given depth
3 1,426.49 701,022.54 0.2% 3.41 construct compound tree of given depth
4 1,695.10 589,935.52 0.4% 4.06 construct compound tree of given depth
5 1,936.56 516,378.66 0.1% 4.62 construct compound tree of given depth
1 6.40 156,141,445.66 1.2% 0.02 type of tree
2 6.56 152,364,108.27 2.4% 0.02 type of tree
3 6.56 152,420,623.15 3.5% 0.02 type of tree
4 6.56 152,408,961.73 3.3% 0.02 type of tree
5 6.72 148,797,187.52 2.7% 0.02 type of tree
1 10.45 95,692,393.95 2.9% 0.03 size of tree
2 10.47 95,489,113.77 2.3% 0.03 size of tree
3 10.59 94,421,383.65 0.7% 0.03 size of tree
4 10.58 94,535,216.47 0.5% 0.03 size of tree
5 10.53 94,952,031.95 0.1% 0.03 size of tree
1 9.18 108,900,726.14 0.2% 0.02 immutable index of tree
2 9.20 108,710,582.01 0.3% 0.02 immutable index of tree
3 9.23 108,307,334.36 0.5% 0.02 immutable index of tree
4 9.19 108,788,564.96 0.4% 0.02 immutable index of tree
5 9.20 108,720,063.44 0.1% 0.02 immutable index of tree
1 124.70 8,019,336.57 2.2% 0.29 mutable index of tree
2 120.40 8,305,652.04 0.9% 0.29 mutable index of tree
3 119.31 8,381,302.47 0.8% 0.29 mutable index of tree
4 118.39 8,446,632.92 1.0% 0.29 mutable index of tree
5 118.64 8,429,087.70 0.3% 0.29 mutable index of tree
1 893.11 1,119,678.75 0.2% 2.14 copy tree
2 903.81 1,106,427.67 0.2% 2.16 copy tree
3 893.81 1,118,802.81 0.3% 2.15 copy tree
4 893.38 1,119,341.18 0.3% 2.14 copy tree
5 890.22 1,123,313.28 0.1% 2.13 copy tree
1 390.42 2,561,319.35 0.3% 0.93 equality of tree
2 386.78 2,585,461.43 0.1% 0.93 equality of tree
3 393.43 2,541,776.30 0.7% 0.94 equality of tree
4 400.66 2,495,883.57 0.1% 0.96 equality of tree
5 399.51 2,503,047.44 0.4% 0.95 equality of tree