From 4395a5e2d58fa1687394808dcbd203c3dfb4e29c Mon Sep 17 00:00:00 2001 From: Christian Ditaputratama Date: Mon, 29 Jul 2024 22:44:10 +0700 Subject: [PATCH] test: Add benchmark Test for `QueryNodes.toSQL()` --- internal/monero/monero_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/internal/monero/monero_test.go b/internal/monero/monero_test.go index 71b1e88..d47ebb0 100644 --- a/internal/monero/monero_test.go +++ b/internal/monero/monero_test.go @@ -35,6 +35,8 @@ func init() { } } +// Single test: +// go test -race ./internal/monero -run=TestQueryNodes_toSQL -v func TestQueryNodes_toSQL(t *testing.T) { tests := []struct { name string @@ -102,6 +104,28 @@ func TestQueryNodes_toSQL(t *testing.T) { } } +// Single bench test: +// go test ./internal/monero -bench QueryNodes_toSQL -benchmem -run=^$ -v +func Benchmark_QueryNodes_toSQL(b *testing.B) { + for i := 0; i < b.N; i++ { + _, _, _, _ = QueryNodes{ + Host: "test", + Nettype: "any", + Protocol: "any", + CC: "any", + Status: -1, + CORS: -1, + RowsPerPage: 10, + Page: 1, + SortBy: "last_checked", + SortDirection: "desc", + }.toSQL() + } +} + +// equalArgs is helper function for testing. +// +// This returns true if two slices of interface{} are equal. func equalArgs(a, b []interface{}) bool { if len(a) != len(b) { return false