From f99a1b9ad40ebc75fcb2c7d055a4f5ac23254281 Mon Sep 17 00:00:00 2001 From: rulego-team Date: Tue, 7 Jul 2026 01:00:29 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E6=96=B0=E5=A2=9E=E4=B8=BB=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E9=9B=86=E6=88=90=E5=9F=BA=E5=87=86=EF=BC=88EmitSync?= =?UTF-8?q?=EF=BC=8C=E7=9C=9F=E5=AE=9E=20RSQL=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FilterProject/MultiFieldFilter/ComputedFields/StringConcat/NoFilter, 用 EmitSync 同步测端到端每行延迟(用户实际调用路径)。 --- streamsql_perf_test.go | 69 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 streamsql_perf_test.go diff --git a/streamsql_perf_test.go b/streamsql_perf_test.go new file mode 100644 index 0000000..a7ec4c0 --- /dev/null +++ b/streamsql_perf_test.go @@ -0,0 +1,69 @@ +package streamsql + +import ( + "testing" +) + +// Integration benchmarks exercising the full main path with realistic RSQL. +// EmitSync processes each row synchronously end-to-end (the same path users +// call), so ns/op is the true per-row latency through ProcessData -> field +// evaluation -> result building. Aggregation queries are exercised separately +// via the Emit-based benchmarks. + +func benchEmitSync(b *testing.B, sql string, row map[string]interface{}) { + b.Helper() + ssql := New() + defer ssql.Stop() + if err := ssql.Execute(sql); err != nil { + b.Fatalf("Execute: %v", err) + } + + // Warm up compile/preprocess caches (do not measure). + if _, err := ssql.EmitSync(row); err != nil { + b.Fatalf("warmup EmitSync: %v", err) + } + + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + if _, err := ssql.EmitSync(row); err != nil { + b.Fatalf("EmitSync: %v", err) + } + } + b.StopTimer() +} + +func BenchmarkMainPath_FilterProject(b *testing.B) { + benchEmitSync(b, + "SELECT deviceId, temperature FROM stream WHERE temperature > 20", + map[string]interface{}{"deviceId": "d1", "temperature": 25.5, "humidity": 60.0}, + ) +} + +func BenchmarkMainPath_MultiFieldFilter(b *testing.B) { + benchEmitSync(b, + "SELECT deviceId, temperature, humidity FROM stream WHERE temperature > 20 AND humidity < 80", + map[string]interface{}{"deviceId": "d1", "temperature": 25.5, "humidity": 60.0}, + ) +} + +func BenchmarkMainPath_ComputedFields(b *testing.B) { + benchEmitSync(b, + "SELECT deviceId, temperature * 2 + humidity AS score, abs(temperature - 100) AS dev FROM stream WHERE temperature > 20", + map[string]interface{}{"deviceId": "d1", "temperature": 25.5, "humidity": 60.0}, + ) +} + +func BenchmarkMainPath_StringConcat(b *testing.B) { + benchEmitSync(b, + "SELECT deviceId + '-' + location AS id FROM stream", + map[string]interface{}{"deviceId": "d1", "location": "roomA"}, + ) +} + +func BenchmarkMainPath_NoFilter(b *testing.B) { + benchEmitSync(b, + "SELECT deviceId, temperature, humidity FROM stream", + map[string]interface{}{"deviceId": "d1", "temperature": 25.5, "humidity": 60.0}, + ) +}