MCPcopy Create free account
hub / github.com/astercloud/aster / BenchmarkMarshalDeterministic

Function BenchmarkMarshalDeterministic

pkg/util/json_test.go:258–281  ·  view source on GitHub ↗

BenchmarkMarshalDeterministic 与标准 json.Marshal 对比

(b *testing.B)

Source from the content-addressed store, hash-verified

256
257// BenchmarkMarshalDeterministic 与标准 json.Marshal 对比
258func BenchmarkMarshalDeterministic(b *testing.B) {
259 m := map[string]any{
260 "zebra": 1,
261 "apple": 2,
262 "mango": 3,
263 "nested": map[string]int{
264 "c": 3,
265 "a": 1,
266 "b": 2,
267 },
268 }
269
270 b.Run("Deterministic", func(b *testing.B) {
271 for i := 0; i < b.N; i++ {
272 _, _ = MarshalDeterministic(m)
273 }
274 })
275
276 b.Run("StandardJSON", func(b *testing.B) {
277 for i := 0; i < b.N; i++ {
278 _, _ = json.Marshal(m)
279 }
280 })
281}
282
283// 验证标准 json.Marshal 确实是不确定的
284func TestStandardJSONIsNonDeterministic(t *testing.T) {

Callers

nothing calls this directly

Calls 2

MarshalDeterministicFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected