Skip to content

Commit

Permalink
add benchmark test
Browse files Browse the repository at this point in the history
  • Loading branch information
usk81 committed Jan 2, 2018
1 parent 90522b8 commit d1e5f50
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion json_unmarshal_benchmark_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package generic

import "testing"
import (
"testing"
"time"
)

func BenchmarkUnmarshalJSONBoolFromBool(b *testing.B) {
unmarshalJSONBoolBenchmark(b, []byte(`true`))
Expand Down Expand Up @@ -70,6 +73,11 @@ func BenchmarkUnmarshalJSONStringFromString(b *testing.B) {
unmarshalJSONStringBenchmark(b, []byte(`"true"`))
}

func BenchmarkUnmarshalJSONTimeFromString(b *testing.B) {
now := time.Now()
unmarshalJSONTimeBenchmark(b, []byte(`"`+now.String()+`"`))
}

func unmarshalJSONBoolBenchmark(b *testing.B, bs []byte) {
x := Bool{}
for i := 0; i < b.N; i++ {
Expand Down Expand Up @@ -98,6 +106,13 @@ func unmarshalJSONStringBenchmark(b *testing.B, bs []byte) {
}
}

func unmarshalJSONTimeBenchmark(b *testing.B, bs []byte) {
t := Time{}
for i := 0; i < b.N; i++ {
t.UnmarshalJSON(bs)
}
}

func unmarshalJSONUintBenchmark(b *testing.B, bs []byte) {
x := Uint{}
for i := 0; i < b.N; i++ {
Expand Down

0 comments on commit d1e5f50

Please sign in to comment.