MCPcopy Create free account
hub / github.com/dop251/goja / BenchmarkJSONStringify

Function BenchmarkJSONStringify

builtin_json_test.go:117–140  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

115}
116
117func BenchmarkJSONStringify(b *testing.B) {
118 b.StopTimer()
119 vm := New()
120 var createObj func(level int) *Object
121 createObj = func(level int) *Object {
122 o := vm.NewObject()
123 o.Set("field1", "test")
124 o.Set("field2", 42)
125 if level > 0 {
126 level--
127 o.Set("obj1", createObj(level))
128 o.Set("obj2", createObj(level))
129 }
130 return o
131 }
132
133 o := createObj(3)
134 json := vm.Get("JSON").(*Object)
135 stringify, _ := AssertFunction(json.Get("stringify"))
136 b.StartTimer()
137 for i := 0; i < b.N; i++ {
138 stringify(nil, o)
139 }
140}

Callers

nothing calls this directly

Calls 5

SetMethod · 0.95
NewFunction · 0.85
AssertFunctionFunction · 0.85
NewObjectMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…