diff --git a/utils/coreutils_test.go b/utils/coreutils_test.go index d278cd00e..b70251364 100644 --- a/utils/coreutils_test.go +++ b/utils/coreutils_test.go @@ -2017,6 +2017,27 @@ func TestGetEndOfMonth(t *testing.T) { } } +// go test ./utils/ -bench BenchmarkToJSON -benchtime=1s -benchmem +func BenchmarkToJSON(b *testing.B) { + v := map[string]any{ + "Result-Code": "2001", + "Granted-Service-Unit": map[string]any{ + "CC-Time": 300, + }, + "Session-Id": "cgrates;1052943642;938", + } + b.Run("ToJSON", func(b *testing.B) { + for b.Loop() { + ToJSON(v) + } + }) + b.Run("ToIJSON", func(b *testing.B) { + for b.Loop() { + ToIJSON(v) + } + }) +} + func TestParseBinarySize(t *testing.T) { type args struct { size string diff --git a/utils/orderednavigablemap.go b/utils/orderednavigablemap.go index e12b5fa66..5ed92f475 100644 --- a/utils/orderednavigablemap.go +++ b/utils/orderednavigablemap.go @@ -42,7 +42,7 @@ type OrderedNavigableMap struct { // String returns the map as json string func (onm *OrderedNavigableMap) String() string { - return ToJSON(onm.nm) + return ToIJSON(onm.nm) } // GetFirstElement returns the first element from the order diff --git a/utils/orderednavigablemap_test.go b/utils/orderednavigablemap_test.go index 8ccb6d92a..0d5f4bb7a 100644 --- a/utils/orderednavigablemap_test.go +++ b/utils/orderednavigablemap_test.go @@ -892,7 +892,15 @@ func TestOrderedNavigableMapString(t *testing.T) { }, }, } - onmExpect := `{"Map":{"test1":{"Value":{"Data":"data!"}}}}` + onmExpect := `{ + "Map": { + "test1": { + "Value": { + "Data": "data!" + } + } + } +}` if onm.String() != onmExpect { t.Errorf("Expected %s but received %s", onmExpect, onm.String()) }