Commit edef28d
authored
Use a custom error type for invalid lengths, replacing
* Add benchmarks for different kinds of invalid UUIDs
Also add a test case for too-short UUIDs to ensure behavior doesn’t
change.
* Use a custom error type for invalid lengths, replacing `fmt.Errorf`
This significantly improves the speed of failed parses due to wrong
lengths. Previously the `fmt.Errorf` call dominated, making this the
most expensive error and more expensive than successfully parsing:
BenchmarkParse-4 29226529 36.1 ns/op
BenchmarkParseBadLength-4 6923106 174 ns/op
BenchmarkParseLen32Truncated-4 26641954 38.1 ns/op
BenchmarkParseLen36Corrupted-4 19405598 59.5 ns/op
When the formatting is not required and done on-demand, the failure per
se is much faster:
BenchmarkParse-4 29641700 36.3 ns/op
BenchmarkParseBadLength-4 58602537 20.0 ns/op
BenchmarkParseLen32Truncated-4 30664791 43.6 ns/op
BenchmarkParseLen36Corrupted-4 18882410 61.9 ns/opfmt.Errorf (#69)1 parent 0e4e311 commit edef28d
2 files changed
+47
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
38 | 44 | | |
39 | 45 | | |
40 | 46 | | |
| |||
68 | 74 | | |
69 | 75 | | |
70 | 76 | | |
71 | | - | |
| 77 | + | |
72 | 78 | | |
73 | 79 | | |
74 | 80 | | |
| |||
112 | 118 | | |
113 | 119 | | |
114 | 120 | | |
115 | | - | |
| 121 | + | |
116 | 122 | | |
117 | 123 | | |
118 | 124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
517 | 517 | | |
518 | 518 | | |
519 | 519 | | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
520 | 529 | | |
521 | 530 | | |
522 | 531 | | |
| |||
595 | 604 | | |
596 | 605 | | |
597 | 606 | | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
0 commit comments