From fefab2e2ccdf36d0c9b025df878eb804762de85f Mon Sep 17 00:00:00 2001 From: thijsheijden <hi@thijsheijden.nl> Date: Tue, 20 Apr 2021 15:33:00 +0200 Subject: [PATCH] Added some benchmarks for query conversion --- .../usecases/convertquery/benchmark_test.go | 152 ++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 internal/usecases/convertquery/benchmark_test.go diff --git a/internal/usecases/convertquery/benchmark_test.go b/internal/usecases/convertquery/benchmark_test.go new file mode 100644 index 0000000..86da73b --- /dev/null +++ b/internal/usecases/convertquery/benchmark_test.go @@ -0,0 +1,152 @@ +package convertquery + +import "testing" + +func BenchmarkConvertEmptyQuery(b *testing.B) { + // Setup for test + // Create query conversion service + service := NewService() + + query := []byte(`{ + "return": { + "entities": [], + "relations": [] + }, + "entities": [], + "relations": [], + "limit": 5000 + }`) + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + service.ConvertQuery(&query) + } +} + +func BenchmarkConvertOneAttributeQuery(b *testing.B) { + // Setup for test + // Create query conversion service + service := NewService() + + query := []byte(`{ + "return": { + "entities": [ + 0 + ], + "relations": [] + }, + "entities": [ + { + "type": "airports", + "constraints": [ + { + "attribute": "state", + "value": "HI", + "dataType": "text", + "matchType": "exact" + } + ] + } + ], + "relations": [], + "limit": 5000 + }`) + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + service.ConvertQuery(&query) + } +} + +func BenchmarkConvertTwoRelationQuery(b *testing.B) { + // Setup for test + // Create query conversion service + service := NewService() + + query := []byte(`{ + "return": { + "entities": [ + 0, + 1, + 2 + ], + "relations": [ + 0, + 1 + ] + }, + "entities": [ + { + "type": "airports", + "constraints": [ + { + "attribute": "city", + "value": "New York", + "dataType": "text", + "matchType": "exact" + } + ] + }, + { + "type": "airports", + "constraints": [ + { + "attribute": "city", + "value": "San Francisco", + "dataType": "text", + "matchType": "exact" + } + ] + }, + { + "type": "airports", + "constraints": [ + { + "attribute": "state", + "value": "HI", + "dataType": "text", + "matchType": "exact" + } + ] + } + ], + "relations": [ + { + "type": "flights", + "depth": { + "min": 1, + "max": 3 + }, + "entityFrom": 2, + "entityTo": 1, + "constraints": [ + { + "attribute": "Day", + "value": "15", + "dataType": "number", + "matchType": "EQ" + } + ] + }, + { + "type": "flights", + "depth": { + "min": 1, + "max": 1 + }, + "entityFrom": 0, + "entityTo": -1, + "constraints": [] + } + ], + "limit": 5000 + }`) + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + service.ConvertQuery(&query) + } +} -- GitLab