github.com/zmap/zcrypto@v0.0.0-20240512203510-0fef58d9a9db/x509/performance_test.go (about)

     1  // Copyright 2015 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package x509
     6  
     7  import (
     8  	"encoding/json"
     9  	"encoding/pem"
    10  	"io/ioutil"
    11  	"testing"
    12  )
    13  
    14  func BenchmarkParse(b *testing.B) {
    15  	fileBytes, _ := ioutil.ReadFile("testdata/davidadrian.org.cert")
    16  	p, _ := pem.Decode(fileBytes)
    17  	for i := 0; i < b.N; i++ {
    18  		ParseCertificate(p.Bytes)
    19  	}
    20  }
    21  
    22  func BenchmarkEncode(b *testing.B) {
    23  	fileBytes, _ := ioutil.ReadFile("testdata/davidadrian.org.cert")
    24  	p, _ := pem.Decode(fileBytes)
    25  	c, _ := ParseCertificate(p.Bytes)
    26  	for i := 0; i < b.N; i++ {
    27  		json.Marshal(c)
    28  	}
    29  }