Skip to content

Commit 4f9f0ca

Browse files
mateusz834gopherbot
authored andcommitted
x509roots/fallback: add init time benchmark
goos: linux goarch: amd64 pkg: golang.org/x/crypto/x509roots/fallback cpu: AMD Ryzen 5 4600G with Radeon Graphics │ /tmp/before │ │ sec/op │ InitTime-12 1.726m ± 0% │ /tmp/before │ │ B/op │ InitTime-12 1.151Mi ± 0% │ /tmp/before │ │ allocs/op │ InitTime-12 11.35k ± 0% For golang/go#73691 Change-Id: Ic932bd7835e50dd5c6adbdf684644afa49bddebc Reviewed-on: https://go-review.googlesource.com/c/crypto/+/676216 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Roland Shoemaker <roland@golang.org> Reviewed-by: Sean Liao <sean@liao.dev> Auto-Submit: Sean Liao <sean@liao.dev> Reviewed-by: Michael Knyszek <mknyszek@google.com>
1 parent eac7cf0 commit 4f9f0ca

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

x509roots/fallback/fallback.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ import (
2626
)
2727

2828
func init() {
29+
x509.SetFallbackRoots(newFallbackCertPool())
30+
}
31+
32+
func newFallbackCertPool() *x509.CertPool {
2933
p := x509.NewCertPool()
3034
for _, c := range mustParse(unparsedCertificates) {
3135
if len(c.constraints) == 0 {
@@ -41,7 +45,7 @@ func init() {
4145
})
4246
}
4347
}
44-
x509.SetFallbackRoots(p)
48+
return p
4549
}
4650

4751
type unparsedCertificate struct {

x509roots/fallback/fallback_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package fallback
2+
3+
import "testing"
4+
5+
// BenchmarkInitTime benchmarks the time it takes to parse all certificates
6+
// in this bundle, it corresponds to the init time of this package.
7+
func BenchmarkInitTime(b *testing.B) {
8+
for range b.N {
9+
newFallbackCertPool()
10+
}
11+
}

0 commit comments

Comments
 (0)