1
0
mirror of https://github.com/json-iterator/go.git synced 2025-01-08 13:06:29 +02:00
json-iterator/jsoniter_float_test.go

47 lines
788 B
Go
Raw Normal View History

2016-12-01 17:25:29 +02:00
package jsoniter
import (
"testing"
"encoding/json"
2016-12-08 04:02:18 +02:00
"fmt"
2016-12-01 17:25:29 +02:00
)
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)
}
}
2016-12-06 04:21:47 +02:00
func Test_float32_1_dot_1_comma(t *testing.T) {
iter := ParseString(`1.1,`)
val := iter.ReadFloat32()
if val != 1.1 {
2016-12-08 04:02:18 +02:00
fmt.Println(iter.Error)
2016-12-06 04:21:47 +02:00
t.Fatal(val)
}
}
2016-12-01 17:25:29 +02:00
func Benchmark_jsoniter_float(b *testing.B) {
2016-12-08 04:02:18 +02:00
b.ReportAllocs()
2016-12-01 17:25:29 +02:00
for n := 0; n < b.N; n++ {
2016-12-08 04:02:18 +02:00
iter := ParseString(`1.1111111111`)
2016-12-01 17:25:29 +02:00
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)
}
}