Skip to content

Commit

Permalink
benchmarks all working!
Browse files Browse the repository at this point in the history
  • Loading branch information
Darren Kellenschwiler authored and sirdeggen committed Sep 8, 2023
1 parent ecbdbe9 commit 224f697
Showing 1 changed file with 75 additions and 3 deletions.
78 changes: 75 additions & 3 deletions spv/ancestry_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,81 @@ func TestEnvelope_Bytes_IsValid(t *testing.T) {
}
}

func benchmarkEnvelopeBinaryFormats(i int, b *testing.B) {
func benchmarkCrunchyNutEnvelopeCerealize(b *testing.B, envelope *Envelope) {
for n := 0; n < b.N; n++ {
// thing we want to test.
fmt.Println("nothing")
_, err := envelope.SpecialKBytes()
if err != nil {
fmt.Print(err)
}
}
}

func benchmarkCrunchyNutEnvelopeDecerealize(b *testing.B, binary []byte) {
for n := 0; n < b.N; n++ {
_, err := NewCrunchyNutEnvelopeFromBytes(binary)
if err != nil {
fmt.Print(err)
}
}
}

func BenchmarkCerealizeCrunchyNut(b *testing.B) {
for _, test := range tests {
j := []byte(test.jsonString)
var e Envelope
err := json.Unmarshal(j, &e)
if err != nil {
assert.Error(b, err, "Couldn't decode jsonString")
}
benchmarkCrunchyNutEnvelopeCerealize(b, &e)
}
}

func BenchmarkDecerealizeCrunchyNut(b *testing.B) {
for _, test := range tests {
binary, err := hex.DecodeString(test.crunchyNutHexString)
if err != nil {
assert.Error(b, err, "Couldn't decode hexString")
}
benchmarkCrunchyNutEnvelopeDecerealize(b, binary)
}
}

func benchmarkSpecialKEnvelopeCerealize(b *testing.B, envelope *Envelope) {
for n := 0; n < b.N; n++ {
_, err := envelope.SpecialKBytes()
if err != nil {
fmt.Print(err)
}
}
}

func benchmarkSpecialKEnvelopeDecerealize(b *testing.B, binary []byte) {
for n := 0; n < b.N; n++ {
_, err := NewSpecialKEnvelopeFromBytes(binary)
if err != nil {
fmt.Print(err)
}
}
}

func BenchmarkCerealizeSpecialK(b *testing.B) {
for _, test := range tests {
j := []byte(test.jsonString)
var e Envelope
err := json.Unmarshal(j, &e)
if err != nil {
assert.Error(b, err, "Couldn't decode jsonString")
}
benchmarkSpecialKEnvelopeCerealize(b, &e)
}
}
func BenchmarkDecerealizeSpecialK(b *testing.B) {
for _, test := range tests {
binary, err := hex.DecodeString(test.specialKHexString)
if err != nil {
assert.Error(b, err, "Couldn't decode hexString")
}
benchmarkSpecialKEnvelopeDecerealize(b, binary)
}
}

0 comments on commit 224f697

Please sign in to comment.