From 4f94850c1d4a18e2ddaaa9f768af5201f36ce5af Mon Sep 17 00:00:00 2001 From: Sven Rebhan <36194019+srebhan@users.noreply.github.com> Date: Thu, 16 Nov 2023 18:14:40 +0100 Subject: [PATCH] chore(parsers.xpath): Add benchmark for CBOR format (#14314) --- plugins/parsers/xpath/parser_test.go | 32 ++++++++++++++++++ .../testcases/cbor_benchmark/expected.out | 2 ++ .../testcases/cbor_benchmark/message.bin | Bin 0 -> 185 bytes .../testcases/cbor_benchmark/telegraf.conf | 20 +++++++++++ 4 files changed, 54 insertions(+) create mode 100644 plugins/parsers/xpath/testcases/cbor_benchmark/expected.out create mode 100644 plugins/parsers/xpath/testcases/cbor_benchmark/message.bin create mode 100644 plugins/parsers/xpath/testcases/cbor_benchmark/telegraf.conf diff --git a/plugins/parsers/xpath/parser_test.go b/plugins/parsers/xpath/parser_test.go index 4d9d4badc..e2fba76bc 100644 --- a/plugins/parsers/xpath/parser_test.go +++ b/plugins/parsers/xpath/parser_test.go @@ -1781,3 +1781,35 @@ func BenchmarkParsingMsgPack(b *testing.B) { _, _ = plugin.Parse(benchmarkDataMsgPack[n%2]) } } + +func BenchmarkParsingCBOR(b *testing.B) { + plugin := &Parser{ + DefaultMetricName: "benchmark", + Format: "xpath_cbor", + NativeTypes: true, + Configs: []Config{ + { + Selection: "//data", + Timestamp: "timestamp", + TimestampFmt: "unix_ns", + Tags: map[string]string{ + "source": "source", + "tags_sdkver": "tags_sdkver", + "tags_platform": "tags_platform", + }, + Fields: map[string]string{ + "value": "value", + }, + }, + }, + Log: testutil.Logger{Name: "parsers.xpath", Quiet: true}, + } + require.NoError(b, plugin.Init()) + + benchmarkData, err := os.ReadFile(filepath.Join("testcases", "cbor_benchmark", "message.bin")) + require.NoError(b, err) + + for n := 0; n < b.N; n++ { + _, _ = plugin.Parse(benchmarkData) + } +} diff --git a/plugins/parsers/xpath/testcases/cbor_benchmark/expected.out b/plugins/parsers/xpath/testcases/cbor_benchmark/expected.out new file mode 100644 index 000000000..8263f7ceb --- /dev/null +++ b/plugins/parsers/xpath/testcases/cbor_benchmark/expected.out @@ -0,0 +1,2 @@ +benchmark,source=myhost,tags_platform=python,tags_sdkver=3.11.5 value=5.0 1653643421000000000 +benchmark,source=myhost,tags_platform=python,tags_sdkver=3.11.4 value=4.0 1653643421000000000 diff --git a/plugins/parsers/xpath/testcases/cbor_benchmark/message.bin b/plugins/parsers/xpath/testcases/cbor_benchmark/message.bin new file mode 100644 index 0000000000000000000000000000000000000000..a447911aed2d7fd23111c78b8adc2dc973a7511b GIT binary patch literal 185 zcmZ3Ol9E`G*t9gQIKQ+gIW;Y}G9$mZB)cRry*R!&CA%!OD9u>U&`{4b7c5kelUS0L zUzD3xP+5|ZpO;#em{Xei+d+f@3^GeHb5n~;5_1cr#Xh}$Cwli013`mL@ER