Skip to content

Commit c2d86ba

Browse files
improve the test consistency
1 parent f125363 commit c2d86ba

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

benchmark/bench.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def run_benchmark(directory: str, is_published: bool, version: str) -> Dict[str,
8686

8787
print(f"{Fore.YELLOW}Running benchmark for {version_name} version...{Style.RESET_ALL}")
8888
try:
89-
result = subprocess.run(["go", "test", "-bench=.", "-benchmem", "-count=5"],
89+
result = subprocess.run(["go", "test", "-bench=.", "-benchmem", "-count=10"],
9090
cwd=directory, check=True, capture_output=True, text=True)
9191
except subprocess.CalledProcessError as e:
9292
print(f"{Fore.RED}Error running benchmark: {e}{Style.RESET_ALL}")

benchmark/benchmark_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package benchmark
33
import (
44
"bytes"
55
"fmt"
6+
"runtime"
67
"strings"
78
"testing"
89

@@ -50,12 +51,33 @@ var TestCases = []struct {
5051
},
5152
}
5253

54+
func performWarmupRuns() {
55+
runtime.GC()
56+
57+
for _, tc := range TestCases {
58+
for i := 0; i < 10; i++ {
59+
logic := strings.NewReader(tc.logic)
60+
data := strings.NewReader(tc.data)
61+
var result bytes.Buffer
62+
_ = jsonlogic.Apply(logic, data, &result)
63+
}
64+
}
65+
66+
runtime.GC()
67+
}
68+
5369
func BenchmarkJSONLogic(b *testing.B) {
70+
performWarmupRuns()
71+
5472
for _, tc := range TestCases {
5573
b.Run(tc.name, func(b *testing.B) {
5674
b.ResetTimer()
5775
b.ReportAllocs()
5876

77+
b.StopTimer()
78+
runtime.GC()
79+
b.StartTimer()
80+
5981
for i := 0; i < b.N; i++ {
6082
logic := strings.NewReader(tc.logic)
6183
data := strings.NewReader(tc.data)

0 commit comments

Comments
 (0)