github.com/sohaha/zlsgo@v1.7.13-0.20240501141223-10dd1a906f76/zjson/json_test.go (about)

     1  package zjson
     2  
     3  import (
     4  	"encoding/json"
     5  	"strconv"
     6  	"testing"
     7  
     8  	"github.com/sohaha/zlsgo/zstring"
     9  )
    10  
    11  func TestMatch(t *testing.T) {
    12  	j := Parse(demo)
    13  	nj := j.MatchKeys([]string{"time", "friends"})
    14  	t.Log(j)
    15  	t.Log(nj)
    16  
    17  	j = Parse("")
    18  	nj = j.MatchKeys([]string{"time", "friends"})
    19  	t.Log(j)
    20  	t.Log(nj)
    21  }
    22  
    23  func getBigJSON() string {
    24  	s := ""
    25  	for i := 0; i < 10000; i++ {
    26  		s, _ = Set(s, strconv.Itoa(i), zstring.Rand(10))
    27  	}
    28  	return s
    29  }
    30  
    31  func BenchmarkUnmarshal1(b *testing.B) {
    32  	var demoData Demo
    33  	demoByte := zstring.String2Bytes(demo)
    34  	b.ResetTimer()
    35  	for i := 0; i < b.N; i++ {
    36  		_ = Unmarshal(demoByte, &demoData)
    37  	}
    38  }
    39  
    40  func BenchmarkGolangUnmarshal(b *testing.B) {
    41  	var demoData Demo
    42  	demoByte := zstring.String2Bytes(demo)
    43  	b.ResetTimer()
    44  	for i := 0; i < b.N; i++ {
    45  		_ = json.Unmarshal(demoByte, &demoData)
    46  	}
    47  }