Selaa lähdekoodia

test: add benchmark for getTuples (#1929)

* add benchmark for getTuples

Signed-off-by: yisaer <disxiaofei@163.com>

* address the comment

Signed-off-by: yisaer <disxiaofei@163.com>

---------

Signed-off-by: yisaer <disxiaofei@163.com>
Song Gao 1 vuosi sitten
vanhempi
commit
4d2760e845
2 muutettua tiedostoa jossa 38843 lisäystä ja 0 poistoa
  1. 39 0
      internal/converter/json/convert_bench_test.go
  2. 38804 0
      internal/converter/json/testdata/MDFD.json

+ 39 - 0
internal/converter/json/convert_bench_test.go

@@ -0,0 +1,39 @@
+// Copyright 2023 EMQ Technologies Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package json
+
+import (
+	"os"
+	"testing"
+)
+
+func BenchmarkSimpleTuples(b *testing.B) {
+	payload := []byte(`{"key": "value"}`)
+	b.ResetTimer()
+	for i := 0; i < b.N; i++ {
+		converter.Decode(payload)
+	}
+}
+
+func BenchmarkComplexTuples(b *testing.B) {
+	payload, err := os.ReadFile("./testdata/MDFD.json")
+	if err != nil {
+		b.Fatalf(err.Error())
+	}
+	b.ResetTimer()
+	for i := 0; i < b.N; i++ {
+		converter.Decode(payload)
+	}
+}

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 38804 - 0
internal/converter/json/testdata/MDFD.json