Created
May 9, 2017 02:42
-
-
Save teraPacket/f02b6b3eaccedd1396add7f1a2b65ee1 to your computer and use it in GitHub Desktop.
Revisions
-
teraPacket created this gist
May 9, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ //With the updated json parsing as of May 8, 2017, the speed of extraction from JSON string increased more than twice: //using old API it took 7.2 seconds, with new API, it took 2.3 sec) //the new API allows decoding JSON with a sequence of field names to specify the element to be extracted. package main import "time" import ( "fmt" "github.com/xiaost/jsonport" ) func main() { jsonstr := `{ "foo": 1, "bar": 2, "test": "Hello, world!", "baz": 123.1, "array": [ {"foo": 1}, {"bar": 2}, {"baz": 3} ], "subobj": { "foo": 1, "subarray": [1,2,3], "subsubobj": { "bar": 2, "baz": 3, "array": ["hello", "world"] } }, "bool": true }`; sum := 1 t0 := time.Now() for sum < 1000000 { jsonport.Unmarshal([]byte(jsonstr), "subobj","subsubobj", "array", 1) sum += 1 } t1 := time.Now() fmt.Printf("The call took %v to run.\n", t1.Sub(t0)) }