1
0
mirror of https://github.com/json-iterator/go.git synced 2024-11-24 08:22:14 +02:00
json-iterator/jsoniter_float_test.go
2016-12-06 10:21:47 +08:00

44 lines
728 B
Go

package jsoniter
import (
"testing"
"encoding/json"
)
func Test_float64_0(t *testing.T) {
iter := ParseString(`0`)
val := iter.ReadFloat64()
if val != 0 {
t.Fatal(val)
}
}
func Test_float64_1_dot_1(t *testing.T) {
iter := ParseString(`1.1`)
val := iter.ReadFloat64()
if val != 1.1 {
t.Fatal(val)
}
}
func Test_float32_1_dot_1_comma(t *testing.T) {
iter := ParseString(`1.1,`)
val := iter.ReadFloat32()
if val != 1.1 {
t.Fatal(val)
}
}
func Benchmark_jsoniter_float(b *testing.B) {
for n := 0; n < b.N; n++ {
iter := ParseString(`1.1`)
iter.ReadFloat64()
}
}
func Benchmark_json_float(b *testing.B) {
for n := 0; n < b.N; n++ {
result := float64(0)
json.Unmarshal([]byte(`1.1`), &result)
}
}