Created
March 11, 2020 09:55
-
-
Save akshaybharambe14/671559a90a785b9c8624a319952fa69f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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