jsoniter_large_file_test.go 840 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package jsoniter
  2. import (
  3. "testing"
  4. "os"
  5. "encoding/json"
  6. "io/ioutil"
  7. )
  8. func Test_large_file(t *testing.T) {
  9. file, err := os.Open("/tmp/large-file.json")
  10. if err != nil {
  11. t.Fatal(err)
  12. }
  13. iter := Parse(file, 4096)
  14. count := 0
  15. for iter.ReadArray() {
  16. iter.Skip()
  17. count++
  18. }
  19. if count != 11351 {
  20. t.Fatal(count)
  21. }
  22. }
  23. func Benchmark_jsoniter_large_file(b *testing.B) {
  24. b.ReportAllocs()
  25. for n := 0; n < b.N; n++ {
  26. file, _ := os.Open("/tmp/large-file.json")
  27. iter := Parse(file, 4096)
  28. count := 0
  29. for iter.ReadArray() {
  30. iter.Skip()
  31. count++
  32. }
  33. file.Close()
  34. }
  35. }
  36. func Benchmark_json_large_file(b *testing.B) {
  37. b.ReportAllocs()
  38. for n := 0; n < b.N; n++ {
  39. file, _ := os.Open("/tmp/large-file.json")
  40. bytes, _ := ioutil.ReadAll(file)
  41. file.Close()
  42. result := []struct{}{}
  43. json.Unmarshal(bytes, &result)
  44. }
  45. }