Skip to content

Instantly share code, notes, and snippets.

@akshaybharambe14
Created March 11, 2020 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akshaybharambe14/671559a90a785b9c8624a319952fa69f to your computer and use it in GitHub Desktop.
Save akshaybharambe14/671559a90a785b9c8624a319952fa69f to your computer and use it in GitHub Desktop.
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