summaryrefslogtreecommitdiff
path: root/benchmarks/benchmark_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-06-25 23:10:24 +0300
committerPaul Buetow <paul@buetow.org>2025-06-25 23:10:24 +0300
commit41ec9cf2942edc7be58d78e49a050131bb2faf8c (patch)
treea3f9dbd423c120f76e629f06524381476e948e9a /benchmarks/benchmark_test.go
parent281360144171c98641f50e938c439915c9b2580a (diff)
Add comprehensive benchmarking framework for DTail
- Create benchmark framework to measure performance of dcat, dgrep, and dmap - Generate test files of 10MB, 100MB, and 1GB with configurable patterns - Support benchmarking with gzip and zstd compressed files - Implement tool-specific benchmarks: * DCat: Simple reading, multiple files, compressed files * DGrep: Pattern matching, regex complexity, context lines, inverted grep * DMap: Aggregations, group by operations, complex queries, time intervals - Track performance metrics: throughput (MB/sec), lines/sec, memory usage - Save results in multiple formats: JSON, CSV, and Markdown reports - Add Makefile targets: benchmark, benchmark-quick, benchmark-full - Support environment variables for configuration (sizes, timeouts, etc.) - Automatically clean up temporary .tmp files after benchmarks The framework provides consistent performance testing across the DTail toolset and enables tracking performance regressions between commits. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'benchmarks/benchmark_test.go')
-rw-r--r--benchmarks/benchmark_test.go69
1 files changed, 69 insertions, 0 deletions
diff --git a/benchmarks/benchmark_test.go b/benchmarks/benchmark_test.go
new file mode 100644
index 0000000..baa53fc
--- /dev/null
+++ b/benchmarks/benchmark_test.go
@@ -0,0 +1,69 @@
+package benchmarks
+
+import (
+ "fmt"
+ "os"
+ "testing"
+)
+
+// TestMain sets up and tears down the benchmark environment
+func TestMain(m *testing.M) {
+ // Clean up any leftover files before starting
+ if err := CleanupBenchmarkFiles(""); err != nil {
+ fmt.Fprintf(os.Stderr, "Warning: failed to cleanup old files: %v\n", err)
+ }
+
+ // Run tests/benchmarks
+ code := m.Run()
+
+ // Clean up after benchmarks unless asked to keep files
+ if os.Getenv("DTAIL_BENCH_KEEP_FILES") != "true" {
+ if err := CleanupBenchmarkFiles(""); err != nil {
+ fmt.Fprintf(os.Stderr, "Warning: failed to cleanup files: %v\n", err)
+ }
+ }
+
+ os.Exit(code)
+}
+
+// BenchmarkAll runs a representative subset of all benchmarks
+func BenchmarkAll(b *testing.B) {
+ b.Run("DCat", func(b *testing.B) {
+ BenchmarkDCatSimple(b)
+ })
+
+ b.Run("DGrep", func(b *testing.B) {
+ BenchmarkDGrepSimplePattern(b)
+ })
+
+ b.Run("DMap", func(b *testing.B) {
+ BenchmarkDMapSimpleAggregation(b)
+ })
+}
+
+// BenchmarkQuick runs only quick benchmarks with small files
+func BenchmarkQuick(b *testing.B) {
+ // Set quick mode
+ oldQuick := os.Getenv("DTAIL_BENCH_QUICK")
+ os.Setenv("DTAIL_BENCH_QUICK", "true")
+ defer func() {
+ if oldQuick == "" {
+ os.Unsetenv("DTAIL_BENCH_QUICK")
+ } else {
+ os.Setenv("DTAIL_BENCH_QUICK", oldQuick)
+ }
+ }()
+
+ // Set small files only
+ oldSizes := os.Getenv("DTAIL_BENCH_SIZES")
+ os.Setenv("DTAIL_BENCH_SIZES", "small")
+ defer func() {
+ if oldSizes == "" {
+ os.Unsetenv("DTAIL_BENCH_SIZES")
+ } else {
+ os.Setenv("DTAIL_BENCH_SIZES", oldSizes)
+ }
+ }()
+
+ BenchmarkAll(b)
+} \ No newline at end of file