-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from jbowes/hashi-bench
Add benchmarks for hashicorp, too
- Loading branch information
Showing
8 changed files
with
134 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
bench/ours.txt | ||
bench/masterminds.txt | ||
bench/hashicorp.txt |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) 2021 James Bowes. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package hashicorp_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/go-version" | ||
) | ||
|
||
// Benchmarks are defined as slices so they run in the same order every time, | ||
// for easier visual comparison. | ||
|
||
func BenchmarkParse(b *testing.B) { | ||
bcs := []struct { | ||
name string | ||
in string | ||
}{ | ||
{"simple", "1.2.3"}, | ||
{"pre", "1.2.3-beta"}, | ||
{"build", "1.2.3+build"}, | ||
{"pre+build", "1.2.3-rc.1+build.info"}, | ||
} | ||
|
||
for _, bc := range bcs { | ||
b.Run(bc.name, func(b *testing.B) { | ||
b.ReportAllocs() | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
_, _ = version.NewVersion(bc.in) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func BenchmarkParseConstraint(b *testing.B) { | ||
bcs := []struct { | ||
name string | ||
in string | ||
}{ | ||
{"equal", "=2.2"}, | ||
{"tilde", "~>2.2.0"}, | ||
{"range", ">=2.2.x, <3.2.0"}, | ||
|
||
// unsupported by go-version | ||
// {"wildcard", "1.x"}, | ||
// {"caret", "^2.2.0"}, | ||
// {"union", "~2.2.0 || =3.3.0"}, | ||
} | ||
|
||
for _, bc := range bcs { | ||
b.Run(bc.name, func(b *testing.B) { | ||
b.ReportAllocs() | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
_, _ = version.NewConstraint(bc.in) | ||
} | ||
}) | ||
} | ||
} |
This file contains 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