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>
This commit is contained in:
committed by
Gopher Robot
parent
eac7cf0d78
commit
4f9f0ca9fc
@@ -26,6 +26,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
x509.SetFallbackRoots(newFallbackCertPool())
|
||||||
|
}
|
||||||
|
|
||||||
|
func newFallbackCertPool() *x509.CertPool {
|
||||||
p := x509.NewCertPool()
|
p := x509.NewCertPool()
|
||||||
for _, c := range mustParse(unparsedCertificates) {
|
for _, c := range mustParse(unparsedCertificates) {
|
||||||
if len(c.constraints) == 0 {
|
if len(c.constraints) == 0 {
|
||||||
@@ -41,7 +45,7 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
x509.SetFallbackRoots(p)
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
type unparsedCertificate struct {
|
type unparsedCertificate struct {
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package fallback
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
// BenchmarkInitTime benchmarks the time it takes to parse all certificates
|
||||||
|
// in this bundle, it corresponds to the init time of this package.
|
||||||
|
func BenchmarkInitTime(b *testing.B) {
|
||||||
|
for range b.N {
|
||||||
|
newFallbackCertPool()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user