From f3d2e6a817d7fe5e3207772135d150bdc2b78646 Mon Sep 17 00:00:00 2001 From: sado Date: Tue, 10 May 2022 18:50:15 +0800 Subject: [PATCH] add benchmark --- kit/rule/benchmark_test.go | 23 +++++++++++++++++++++++ kit/rule/parser.go | 5 +++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 kit/rule/benchmark_test.go diff --git a/kit/rule/benchmark_test.go b/kit/rule/benchmark_test.go new file mode 100644 index 0000000..e912332 --- /dev/null +++ b/kit/rule/benchmark_test.go @@ -0,0 +1,23 @@ +package rule + +import ( + "context" + "testing" +) + +func Benchmark_SingleParse(bench *testing.B) { + + for i := 0; i < bench.N; i++ { + New(context.Background(), "1") + } +} + +func Benchmark_Single(bench *testing.B) { + + parser, _ := New(context.Background(), "1") + + bench.ResetTimer() + for i := 0; i < bench.N; i++ { + parser.Eval(nil) + } +} diff --git a/kit/rule/parser.go b/kit/rule/parser.go index f0edd94..6e4d562 100644 --- a/kit/rule/parser.go +++ b/kit/rule/parser.go @@ -5,6 +5,7 @@ import ( "fmt" "go/scanner" "go/token" + "io" "log" "os" "strings" @@ -16,8 +17,8 @@ var ( ) func init() { - //logger.SetFlags(0) - //logger.SetOutput(io.Discard) + logger.SetFlags(0) + logger.SetOutput(io.Discard) } type (