summaryrefslogtreecommitdiff
path: root/benchmarks/benchmark_test.go
blob: baa53fc58e75d637975ff56049717a01d8e8cb65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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)
}