summaryrefslogtreecommitdiff
path: root/benchmarks/buffer_pool_test.go
blob: 144a92c8adce9e7bbde055fb0a07599365ec4724 (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
70
71
72
73
74
75
76
77
78
79
80
package benchmarks

import (
	"os"
	"testing"
)

// BenchmarkDGrepMultipleFiles tests buffer pooling effectiveness with multiple files
func BenchmarkDGrepMultipleFiles(b *testing.B) {
	cleanup := SetupBenchmark(b)
	defer cleanup()

	// Create multiple test files
	numFiles := 10
	files := make([]string, numFiles)
	for i := 0; i < numFiles; i++ {
		config := TestDataConfig{
			Size:          Small,
			Format:        SimpleLogFormat,
			Compression:   NoCompression,
			LineVariation: 50,
			Pattern:       "ERROR",
			PatternRate:   10,
		}
		files[i] = GenerateTestFile(b, config)
		defer os.Remove(files[i])
	}

	b.Run("WithTurbo", func(b *testing.B) {
		os.Setenv("DTAIL_TURBOBOOST_ENABLE", "yes")
		defer os.Unsetenv("DTAIL_TURBOBOOST_ENABLE")

		b.ResetTimer()
		b.ReportAllocs()

		for i := 0; i < b.N; i++ {
			// Process all files
			for _, file := range files {
				_, err := RunBenchmarkCommand(b, "dgrep", "--plain", "--cfg", "none", "--grep", "ERROR", file)
				if err != nil {
					b.Fatalf("Failed to run dgrep: %v", err)
				}
			}
		}
	})
}

// BenchmarkDGrepLargeFile tests performance on a single large file
func BenchmarkDGrepLargeFile(b *testing.B) {
	cleanup := SetupBenchmark(b)
	defer cleanup()

	config := TestDataConfig{
		Size:          Medium,
		Format:        SimpleLogFormat,
		Compression:   NoCompression,
		LineVariation: 50,
		Pattern:       "ERROR",
		PatternRate:   10,
	}
	
	testFile := GenerateTestFile(b, config)
	defer os.Remove(testFile)

	b.Run("WithTurbo", func(b *testing.B) {
		os.Setenv("DTAIL_TURBOBOOST_ENABLE", "yes")
		defer os.Unsetenv("DTAIL_TURBOBOOST_ENABLE")

		b.ResetTimer()
		b.ReportAllocs()

		for i := 0; i < b.N; i++ {
			result, err := RunBenchmarkCommand(b, "dgrep", "--plain", "--cfg", "none", "--grep", "ERROR", testFile)
			if err != nil {
				b.Fatalf("Failed to run dgrep: %v", err)
			}
			_ = result
		}
	})
}