github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/pkg/scanners/azure/arm/parser/armjson/bench_test.go (about) 1 package armjson 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 "github.com/khulnasoft-lab/defsec/pkg/types" 8 9 "github.com/stretchr/testify/require" 10 ) 11 12 func BenchmarkUnmarshal_JFather(b *testing.B) { 13 target := make(map[string]interface{}) 14 input := []byte(`{ 15 "glossary": { 16 "title": "example glossary", 17 "GlossDiv": { 18 "title": "S", 19 "GlossList": { 20 "GlossEntry": { 21 "ID": "SGML", 22 "SortAs": "SGML", 23 "GlossTerm": "Standard Generalized Markup Language", 24 "Acronym": "SGML", 25 "Abbrev": "ISO 8879:1986", 26 "GlossDef": { 27 "para": "A meta-markup language, used to create markup languages such as DocBook.", 28 "GlossSeeAlso": ["GML", "XML"] 29 }, 30 "GlossSee": "markup" 31 } 32 } 33 } 34 } 35 }`) 36 37 for n := 0; n < b.N; n++ { 38 metadata := types.NewTestMetadata() 39 require.NoError(b, Unmarshal(input, &target, &metadata)) 40 } 41 } 42 43 func BenchmarkUnmarshal_Traditional(b *testing.B) { 44 target := make(map[string]interface{}) 45 input := []byte(`{ 46 "glossary": { 47 "title": "example glossary", 48 "GlossDiv": { 49 "title": "S", 50 "GlossList": { 51 "GlossEntry": { 52 "ID": "SGML", 53 "SortAs": "SGML", 54 "GlossTerm": "Standard Generalized Markup Language", 55 "Acronym": "SGML", 56 "Abbrev": "ISO 8879:1986", 57 "GlossDef": { 58 "para": "A meta-markup language, used to create markup languages such as DocBook.", 59 "GlossSeeAlso": ["GML", "XML"] 60 }, 61 "GlossSee": "markup" 62 } 63 } 64 } 65 } 66 }`) 67 68 for n := 0; n < b.N; n++ { 69 require.NoError(b, json.Unmarshal(input, &target)) 70 } 71 }