Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package main
import (
"testing"
"github.com/tidwall/sjson"
"github.com/tidwall/gjson"
)
var s = `
{
"name": "Karthic",
"age": 28
}
`
var gp = gjson.Parse(s)
func BenchmarkSetGSJON(b *testing.B) {
for i := 0; i < b.N; i++ {
ip := gp.String()
ip, _ = sjson.Set(ip, "test1", "value")
op := gjson.Parse(ip)
v := op.Value()
_ = v
}
}
func BenchmarkValue(b *testing.B) {
for i := 0; i < b.N; i++ {
v, _ := gp.Value().(map[string]interface{})
v["test1"] = "value"
_ = v
}
}
func BenchmarkSetGSJONMultiple(b *testing.B) {
for i := 0; i < b.N; i++ {
ip := gp.String()
ip, _ = sjson.Set(ip, "test1", "value")
ip, _ = sjson.Set(ip, "test2", "value")
ip, _ = sjson.Set(ip, "test3", "value")
ip, _ = sjson.Set(ip, "test4", "value")
op := gjson.Parse(ip)
v := op.Value()
_ = v
}
}
func BenchmarkValueMultiple(b *testing.B) {
for i := 0; i < b.N; i++ {
v, _ := gp.Value().(map[string]interface{})
v["test1"] = "value"
v["test2"] = "value"
v["test3"] = "value"
v["test4"] = "value"
_ = v
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.