setof speed improvement and tests#420
Merged
klauspost merged 2 commits intotinylib:masterfrom Nov 18, 2025
Merged
Conversation
* Add tests/benchmarks * Use `slices.SortFunc` - slightly faster on non-strings. * Ensure MarshalMsg output can hold the output. * Minor cleanups. ``` benchmark old ns/op new ns/op delta BenchmarkStringSorted_EncodeMsg/10-32 212 203 -4.39% BenchmarkStringSorted_EncodeMsg/100-32 3893 3863 -0.77% BenchmarkStringSorted_EncodeMsg/1000-32 65046 64905 -0.22% BenchmarkStringSorted_DecodeMsg/10-32 617 628 +1.75% BenchmarkStringSorted_DecodeMsg/100-32 2996 3011 +0.50% BenchmarkStringSorted_DecodeMsg/1000-32 29909 30096 +0.63% BenchmarkStringSorted_MarshalMsg/10-32 246 269 +9.05% BenchmarkStringSorted_MarshalMsg/100-32 3991 4295 +7.62% BenchmarkStringSorted_MarshalMsg/1000-32 65655 69870 +6.42% BenchmarkStringSorted_UnmarshalMsg/10-32 290 290 +0.17% BenchmarkStringSorted_UnmarshalMsg/100-32 2522 2521 -0.04% BenchmarkStringSorted_UnmarshalMsg/1000-32 28134 27928 -0.73% BenchmarkStringSorted_AsSlice/10-32 233 163 -30.09% BenchmarkStringSorted_AsSlice/100-32 4318 3357 -22.26% BenchmarkStringSorted_AsSlice/1000-32 73060 61074 -16.41% BenchmarkStringSorted_FromSlice/10-32 158 160 +1.26% BenchmarkStringSorted_FromSlice/100-32 1083 1109 +2.40% BenchmarkStringSorted_FromSlice/1000-32 12169 12340 +1.41% BenchmarkIntSorted_EncodeMsg/10-32 192 143 -25.50% BenchmarkIntSorted_EncodeMsg/100-32 2705 2471 -8.65% BenchmarkIntSorted_EncodeMsg/1000-32 51959 47962 -7.69% BenchmarkIntSorted_DecodeMsg/10-32 548 526 -3.96% BenchmarkIntSorted_DecodeMsg/100-32 1492 1496 +0.27% BenchmarkIntSorted_DecodeMsg/1000-32 12371 12324 -0.38% BenchmarkIntSorted_MarshalMsg/10-32 205 150 -26.99% BenchmarkIntSorted_MarshalMsg/100-32 2662 2461 -7.55% BenchmarkIntSorted_MarshalMsg/1000-32 52221 48179 -7.74% BenchmarkIntSorted_UnmarshalMsg/10-32 153 156 +1.97% BenchmarkIntSorted_UnmarshalMsg/100-32 977 987 +1.01% BenchmarkIntSorted_UnmarshalMsg/1000-32 10424 10462 +0.36% BenchmarkIntSorted_AsSlice/10-32 170 119 -30.09% BenchmarkIntSorted_AsSlice/100-32 2472 2199 -11.04% BenchmarkIntSorted_AsSlice/1000-32 49548 46049 -7.06% BenchmarkIntSorted_FromSlice/10-32 140 138 -1.29% BenchmarkIntSorted_FromSlice/100-32 926 932 +0.69% BenchmarkIntSorted_FromSlice/1000-32 9589 9478 -1.16% BenchmarkUintSorted_EncodeMsg/10-32 190 129 -32.23% BenchmarkUintSorted_EncodeMsg/100-32 2591 2340 -9.69% BenchmarkUintSorted_EncodeMsg/1000-32 52587 48173 -8.39% BenchmarkUintSorted_DecodeMsg/10-32 534 536 +0.26% BenchmarkUintSorted_DecodeMsg/100-32 1482 1492 +0.67% BenchmarkUintSorted_DecodeMsg/1000-32 12374 12417 +0.35% BenchmarkUintSorted_MarshalMsg/10-32 192 140 -27.14% BenchmarkUintSorted_MarshalMsg/100-32 2695 2440 -9.46% BenchmarkUintSorted_MarshalMsg/1000-32 52282 47950 -8.29% BenchmarkUintSorted_UnmarshalMsg/10-32 151 153 +1.46% BenchmarkUintSorted_UnmarshalMsg/100-32 976 987 +1.07% BenchmarkUintSorted_UnmarshalMsg/1000-32 10355 10982 +6.06% BenchmarkUintSorted_AsSlice/10-32 163 119 -26.81% BenchmarkUintSorted_AsSlice/100-32 2396 2189 -8.64% BenchmarkUintSorted_AsSlice/1000-32 49923 46339 -7.18% BenchmarkUintSorted_FromSlice/10-32 138 141 +2.32% BenchmarkUintSorted_FromSlice/100-32 918 975 +6.29% BenchmarkUintSorted_FromSlice/1000-32 9445 9947 +5.31% BenchmarkByteSorted_EncodeMsg/10-32 174 122 -30.29% BenchmarkByteSorted_EncodeMsg/100-32 2565 2297 -10.45% BenchmarkByteSorted_EncodeMsg/1000-32 10087 9210 -8.69% BenchmarkByteSorted_DecodeMsg/10-32 556 568 +2.27% BenchmarkByteSorted_DecodeMsg/100-32 2183 2195 +0.55% BenchmarkByteSorted_DecodeMsg/1000-32 4792 4835 +0.90% BenchmarkByteSorted_MarshalMsg/10-32 178 120 -32.71% BenchmarkByteSorted_MarshalMsg/100-32 2552 2211 -13.36% BenchmarkByteSorted_MarshalMsg/1000-32 10094 8908 -11.75% BenchmarkByteSorted_UnmarshalMsg/10-32 212 212 -0.33% BenchmarkByteSorted_UnmarshalMsg/100-32 1751 1757 +0.34% BenchmarkByteSorted_UnmarshalMsg/1000-32 4247 4257 +0.24% BenchmarkByteSorted_AsSlice/10-32 147 101 -31.61% BenchmarkByteSorted_AsSlice/100-32 2298 2062 -10.27% BenchmarkByteSorted_AsSlice/1000-32 9505 8617 -9.34% BenchmarkByteSorted_FromSlice/10-32 189 191 +1.27% BenchmarkByteSorted_FromSlice/100-32 1710 1705 -0.29% BenchmarkByteSorted_FromSlice/1000-32 15630 15669 +0.25% BenchmarkInt8Sorted_EncodeMsg/10-32 176 124 -29.61% BenchmarkInt8Sorted_EncodeMsg/100-32 2576 2299 -10.75% BenchmarkInt8Sorted_EncodeMsg/1000-32 9862 9153 -7.19% BenchmarkInt8Sorted_DecodeMsg/10-32 556 563 +1.17% BenchmarkInt8Sorted_DecodeMsg/100-32 2138 2148 +0.47% BenchmarkInt8Sorted_DecodeMsg/1000-32 4798 4815 +0.35% BenchmarkInt8Sorted_MarshalMsg/10-32 197 128 -35.28% BenchmarkInt8Sorted_MarshalMsg/100-32 2578 2292 -11.09% BenchmarkInt8Sorted_MarshalMsg/1000-32 10138 9234 -8.92% BenchmarkInt8Sorted_UnmarshalMsg/10-32 213 213 +0.00% BenchmarkInt8Sorted_UnmarshalMsg/100-32 1756 1762 +0.34% BenchmarkInt8Sorted_UnmarshalMsg/1000-32 4319 4316 -0.07% BenchmarkInt8Sorted_AsSlice/10-32 142 105 -26.07% BenchmarkInt8Sorted_AsSlice/100-32 2415 2062 -14.62% BenchmarkInt8Sorted_AsSlice/1000-32 9573 8741 -8.69% BenchmarkInt8Sorted_FromSlice/10-32 190 190 +0.00% BenchmarkInt8Sorted_FromSlice/100-32 1711 1700 -0.64% BenchmarkInt8Sorted_FromSlice/1000-32 15669 15624 -0.29% BenchmarkUint8Sorted_EncodeMsg/10-32 176 114 -35.09% BenchmarkUint8Sorted_EncodeMsg/100-32 2553 2212 -13.36% BenchmarkUint8Sorted_EncodeMsg/1000-32 9998 9314 -6.84% BenchmarkUint8Sorted_DecodeMsg/10-32 552 563 +1.86% BenchmarkUint8Sorted_DecodeMsg/100-32 2181 2200 +0.87% BenchmarkUint8Sorted_DecodeMsg/1000-32 4792 4801 +0.19% BenchmarkUint8Sorted_MarshalMsg/10-32 187 107 -42.85% BenchmarkUint8Sorted_MarshalMsg/100-32 2640 2194 -16.89% BenchmarkUint8Sorted_MarshalMsg/1000-32 10076 9210 -8.59% BenchmarkUint8Sorted_UnmarshalMsg/10-32 215 215 +0.05% BenchmarkUint8Sorted_UnmarshalMsg/100-32 1803 1808 +0.28% BenchmarkUint8Sorted_UnmarshalMsg/1000-32 4394 4413 +0.43% BenchmarkUint8Sorted_AsSlice/10-32 147 92.5 -36.92% BenchmarkUint8Sorted_AsSlice/100-32 2340 2085 -10.90% BenchmarkUint8Sorted_AsSlice/1000-32 9405 8631 -8.23% BenchmarkUint8Sorted_FromSlice/10-32 189 189 +0.32% BenchmarkUint8Sorted_FromSlice/100-32 1710 1710 +0.00% BenchmarkUint8Sorted_FromSlice/1000-32 15675 15674 -0.01% BenchmarkInt16Sorted_EncodeMsg/10-32 179 132 -26.20% BenchmarkInt16Sorted_EncodeMsg/100-32 2701 2365 -12.44% BenchmarkInt16Sorted_EncodeMsg/1000-32 51059 48068 -5.86% BenchmarkInt16Sorted_DecodeMsg/10-32 561 566 +0.86% BenchmarkInt16Sorted_DecodeMsg/100-32 2164 2167 +0.14% BenchmarkInt16Sorted_DecodeMsg/1000-32 19649 19796 +0.75% BenchmarkInt16Sorted_MarshalMsg/10-32 208 132 -36.66% BenchmarkInt16Sorted_MarshalMsg/100-32 2684 2338 -12.89% BenchmarkInt16Sorted_MarshalMsg/1000-32 51687 47348 -8.39% BenchmarkInt16Sorted_UnmarshalMsg/10-32 217 216 -0.41% BenchmarkInt16Sorted_UnmarshalMsg/100-32 1806 1816 +0.55% BenchmarkInt16Sorted_UnmarshalMsg/1000-32 18727 18555 -0.92% BenchmarkInt16Sorted_AsSlice/10-32 155 115 -25.92% BenchmarkInt16Sorted_AsSlice/100-32 2401 2148 -10.54% BenchmarkInt16Sorted_AsSlice/1000-32 49032 45245 -7.72% BenchmarkInt16Sorted_FromSlice/10-32 141 143 +1.21% BenchmarkInt16Sorted_FromSlice/100-32 1099 1108 +0.82% BenchmarkInt16Sorted_FromSlice/1000-32 10972 11142 +1.55% BenchmarkUint16Sorted_EncodeMsg/10-32 180 119 -33.59% BenchmarkUint16Sorted_EncodeMsg/100-32 2572 2363 -8.13% BenchmarkUint16Sorted_EncodeMsg/1000-32 51598 47780 -7.40% BenchmarkUint16Sorted_DecodeMsg/10-32 572 568 -0.68% BenchmarkUint16Sorted_DecodeMsg/100-32 2241 2233 -0.36% BenchmarkUint16Sorted_DecodeMsg/1000-32 20000 20276 +1.38% BenchmarkUint16Sorted_MarshalMsg/10-32 188 125 -33.74% BenchmarkUint16Sorted_MarshalMsg/100-32 2543 2330 -8.38% BenchmarkUint16Sorted_MarshalMsg/1000-32 51485 47576 -7.59% BenchmarkUint16Sorted_UnmarshalMsg/10-32 218 218 +0.00% BenchmarkUint16Sorted_UnmarshalMsg/100-32 1826 1839 +0.71% BenchmarkUint16Sorted_UnmarshalMsg/1000-32 18716 18768 +0.28% BenchmarkUint16Sorted_AsSlice/10-32 151 107 -29.59% BenchmarkUint16Sorted_AsSlice/100-32 2349 2116 -9.92% BenchmarkUint16Sorted_AsSlice/1000-32 49028 45539 -7.12% BenchmarkUint16Sorted_FromSlice/10-32 142 143 +0.56% BenchmarkUint16Sorted_FromSlice/100-32 1098 1102 +0.36% BenchmarkUint16Sorted_FromSlice/1000-32 11103 11145 +0.38% BenchmarkInt32Sorted_EncodeMsg/10-32 193 145 -24.88% BenchmarkInt32Sorted_EncodeMsg/100-32 2678 2344 -12.47% BenchmarkInt32Sorted_EncodeMsg/1000-32 51852 47827 -7.76% BenchmarkInt32Sorted_DecodeMsg/10-32 524 532 +1.59% BenchmarkInt32Sorted_DecodeMsg/100-32 1391 1419 +2.01% BenchmarkInt32Sorted_DecodeMsg/1000-32 11500 11323 -1.54% BenchmarkInt32Sorted_MarshalMsg/10-32 199 144 -27.62% BenchmarkInt32Sorted_MarshalMsg/100-32 2597 2340 -9.90% BenchmarkInt32Sorted_MarshalMsg/1000-32 52071 47451 -8.87% BenchmarkInt32Sorted_UnmarshalMsg/10-32 143 143 +0.35% BenchmarkInt32Sorted_UnmarshalMsg/100-32 946 952 +0.62% BenchmarkInt32Sorted_UnmarshalMsg/1000-32 9359 9423 +0.68% BenchmarkInt32Sorted_AsSlice/10-32 165 113 -31.55% BenchmarkInt32Sorted_AsSlice/100-32 2395 2132 -10.98% BenchmarkInt32Sorted_AsSlice/1000-32 49651 45541 -8.28% BenchmarkInt32Sorted_FromSlice/10-32 124 126 +1.61% BenchmarkInt32Sorted_FromSlice/100-32 862 862 +0.06% BenchmarkInt32Sorted_FromSlice/1000-32 8227 8159 -0.83% BenchmarkUint32Sorted_EncodeMsg/10-32 176 142 -19.01% BenchmarkUint32Sorted_EncodeMsg/100-32 2632 2273 -13.64% BenchmarkUint32Sorted_EncodeMsg/1000-32 51857 47461 -8.48% BenchmarkUint32Sorted_DecodeMsg/10-32 533 533 +0.04% BenchmarkUint32Sorted_DecodeMsg/100-32 1409 1417 +0.57% BenchmarkUint32Sorted_DecodeMsg/1000-32 11482 11210 -2.37% BenchmarkUint32Sorted_MarshalMsg/10-32 198 142 -28.20% BenchmarkUint32Sorted_MarshalMsg/100-32 2575 2319 -9.94% BenchmarkUint32Sorted_MarshalMsg/1000-32 52352 47407 -9.45% BenchmarkUint32Sorted_UnmarshalMsg/10-32 158 144 -8.62% BenchmarkUint32Sorted_UnmarshalMsg/100-32 1107 956 -13.60% BenchmarkUint32Sorted_UnmarshalMsg/1000-32 10596 10779 +1.73% BenchmarkUint32Sorted_AsSlice/10-32 175 116 -33.58% BenchmarkUint32Sorted_AsSlice/100-32 2469 2212 -10.41% BenchmarkUint32Sorted_AsSlice/1000-32 50517 47107 -6.75% BenchmarkUint32Sorted_FromSlice/10-32 135 137 +1.18% BenchmarkUint32Sorted_FromSlice/100-32 923 935 +1.30% BenchmarkUint32Sorted_FromSlice/1000-32 8905 9101 +2.20% BenchmarkInt64Sorted_EncodeMsg/10-32 207 156 -24.46% BenchmarkInt64Sorted_EncodeMsg/100-32 2833 2658 -6.18% BenchmarkInt64Sorted_EncodeMsg/1000-32 57355 50588 -11.80% BenchmarkInt64Sorted_DecodeMsg/10-32 615 624 +1.43% BenchmarkInt64Sorted_DecodeMsg/100-32 1693 1710 +1.00% BenchmarkInt64Sorted_DecodeMsg/1000-32 13748 13940 +1.40% BenchmarkInt64Sorted_MarshalMsg/10-32 216 164 -23.75% BenchmarkInt64Sorted_MarshalMsg/100-32 2804 2724 -2.85% BenchmarkInt64Sorted_MarshalMsg/1000-32 54654 53007 -3.01% BenchmarkInt64Sorted_UnmarshalMsg/10-32 174 178 +2.59% BenchmarkInt64Sorted_UnmarshalMsg/100-32 1100 1116 +1.45% BenchmarkInt64Sorted_UnmarshalMsg/1000-32 12255 12185 -0.57% BenchmarkInt64Sorted_AsSlice/10-32 173 122 -29.59% BenchmarkInt64Sorted_AsSlice/100-32 2720 2408 -11.47% BenchmarkInt64Sorted_AsSlice/1000-32 51257 48403 -5.57% BenchmarkInt64Sorted_FromSlice/10-32 155 157 +1.23% BenchmarkInt64Sorted_FromSlice/100-32 1044 1051 +0.67% BenchmarkInt64Sorted_FromSlice/1000-32 11198 11641 +3.96% BenchmarkUint64Sorted_EncodeMsg/10-32 207 159 -23.37% BenchmarkUint64Sorted_EncodeMsg/100-32 2793 2770 -0.82% BenchmarkUint64Sorted_EncodeMsg/1000-32 53759 50802 -5.50% BenchmarkUint64Sorted_DecodeMsg/10-32 660 676 +2.39% BenchmarkUint64Sorted_DecodeMsg/100-32 1776 1782 +0.34% BenchmarkUint64Sorted_DecodeMsg/1000-32 14571 14678 +0.73% BenchmarkUint64Sorted_MarshalMsg/10-32 212 164 -22.91% BenchmarkUint64Sorted_MarshalMsg/100-32 2889 2665 -7.75% BenchmarkUint64Sorted_MarshalMsg/1000-32 54186 50858 -6.14% BenchmarkUint64Sorted_UnmarshalMsg/10-32 177 179 +0.96% BenchmarkUint64Sorted_UnmarshalMsg/100-32 1124 1143 +1.69% BenchmarkUint64Sorted_UnmarshalMsg/1000-32 12460 12793 +2.67% BenchmarkUint64Sorted_AsSlice/10-32 186 119 -36.25% BenchmarkUint64Sorted_AsSlice/100-32 2607 2368 -9.17% BenchmarkUint64Sorted_AsSlice/1000-32 51618 48003 -7.00% BenchmarkUint64Sorted_FromSlice/10-32 158 160 +1.39% BenchmarkUint64Sorted_FromSlice/100-32 1073 1069 -0.37% BenchmarkUint64Sorted_FromSlice/1000-32 11172 11630 +4.10% BenchmarkFloat64Sorted_EncodeMsg/10-32 199 150 -24.22% BenchmarkFloat64Sorted_EncodeMsg/100-32 2940 2760 -6.12% BenchmarkFloat64Sorted_EncodeMsg/1000-32 57184 55369 -3.17% BenchmarkFloat64Sorted_DecodeMsg/10-32 760 793 +4.32% BenchmarkFloat64Sorted_DecodeMsg/100-32 2873 2913 +1.39% BenchmarkFloat64Sorted_DecodeMsg/1000-32 27272 27727 +1.67% BenchmarkFloat64Sorted_MarshalMsg/10-32 274 172 -37.11% BenchmarkFloat64Sorted_MarshalMsg/100-32 3191 3010 -5.67% BenchmarkFloat64Sorted_MarshalMsg/1000-32 60777 56777 -6.58% BenchmarkFloat64Sorted_UnmarshalMsg/10-32 259 262 +1.08% BenchmarkFloat64Sorted_UnmarshalMsg/100-32 2131 2176 +2.11% BenchmarkFloat64Sorted_UnmarshalMsg/1000-32 22264 22952 +3.09% BenchmarkFloat64Sorted_AsSlice/10-32 171 123 -28.10% BenchmarkFloat64Sorted_AsSlice/100-32 2712 2561 -5.57% BenchmarkFloat64Sorted_AsSlice/1000-32 54985 53087 -3.45% BenchmarkFloat64Sorted_FromSlice/10-32 222 237 +7.04% BenchmarkFloat64Sorted_FromSlice/100-32 1913 1942 +1.52% BenchmarkFloat64Sorted_FromSlice/1000-32 22761 23455 +3.05% BenchmarkFloat32Sorted_EncodeMsg/10-32 193 135 -29.96% BenchmarkFloat32Sorted_EncodeMsg/100-32 2890 2624 -9.20% BenchmarkFloat32Sorted_EncodeMsg/1000-32 56231 53821 -4.29% BenchmarkFloat32Sorted_DecodeMsg/10-32 715 736 +2.87% BenchmarkFloat32Sorted_DecodeMsg/100-32 2527 2542 +0.59% BenchmarkFloat32Sorted_DecodeMsg/1000-32 22848 23154 +1.34% BenchmarkFloat32Sorted_MarshalMsg/10-32 260 151 -42.08% BenchmarkFloat32Sorted_MarshalMsg/100-32 3029 2848 -5.98% BenchmarkFloat32Sorted_MarshalMsg/1000-32 58618 54510 -7.01% BenchmarkFloat32Sorted_UnmarshalMsg/10-32 237 241 +1.43% BenchmarkFloat32Sorted_UnmarshalMsg/100-32 1976 1989 +0.66% BenchmarkFloat32Sorted_UnmarshalMsg/1000-32 20990 21158 +0.80% BenchmarkFloat32Sorted_AsSlice/10-32 168 114 -31.93% BenchmarkFloat32Sorted_AsSlice/100-32 2621 2506 -4.39% BenchmarkFloat32Sorted_AsSlice/1000-32 54476 52322 -3.95% BenchmarkFloat32Sorted_FromSlice/10-32 202 205 +1.58% BenchmarkFloat32Sorted_FromSlice/100-32 1797 1830 +1.84% BenchmarkFloat32Sorted_FromSlice/1000-32 21163 21556 +1.86% ```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
slices.SortFunc- slightly faster on non-strings.