From 2f09915d3da7a23574e1a90fa70eb1af1cdf830a Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 3 May 2026 23:28:57 +0300 Subject: initial stuff --- internal/cpu/stresser_bench_test.go | 114 ++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 internal/cpu/stresser_bench_test.go (limited to 'internal/cpu/stresser_bench_test.go') diff --git a/internal/cpu/stresser_bench_test.go b/internal/cpu/stresser_bench_test.go new file mode 100644 index 0000000..042b6f2 --- /dev/null +++ b/internal/cpu/stresser_bench_test.go @@ -0,0 +1,114 @@ +package cpu + +import ( + "context" + "testing" +) + +func benchmarkStress(b *testing.B, stressFunc func(context.Context, int), intensity int) { + b.Helper() + ctx := context.Background() + for i := 0; i < b.N; i++ { + stressFunc(ctx, intensity) + } +} + +func BenchmarkStressPrime(b *testing.B) { + s := New(Config{ + Mode: ModePrime, + Workers: 1, + IntensityMin: 100, + IntensityMax: 1000, + }) + benchmarkStress(b, s.stressPrime, 100) +} + +func BenchmarkStressMatrix(b *testing.B) { + s := New(Config{ + Mode: ModeMatrix, + Workers: 1, + IntensityMin: 10, + IntensityMax: 50, + }) + benchmarkStress(b, s.stressMatrix, 50) +} + +func BenchmarkStressHash(b *testing.B) { + s := New(Config{ + Mode: ModeHash, + Workers: 1, + IntensityMin: 100, + IntensityMax: 1000, + }) + benchmarkStress(b, s.stressHash, 100) +} + +func BenchmarkStressBitwise(b *testing.B) { + s := New(Config{ + Mode: ModeBitwise, + Workers: 1, + IntensityMin: 100, + IntensityMax: 1000, + }) + benchmarkStress(b, s.stressBitwise, 100) +} + +func BenchmarkStressFloat(b *testing.B) { + s := New(Config{ + Mode: ModeFloat, + Workers: 1, + IntensityMin: 100, + IntensityMax: 1000, + }) + benchmarkStress(b, s.stressFloat, 100) +} + +func BenchmarkStressRecurse(b *testing.B) { + s := New(Config{ + Mode: ModeRecurse, + Workers: 1, + IntensityMin: 10, + IntensityMax: 30, + }) + benchmarkStress(b, s.stressRecurse, 25) +} + +func BenchmarkStressCompress(b *testing.B) { + s := New(Config{ + Mode: ModeCompress, + Workers: 1, + IntensityMin: 100, + IntensityMax: 1000, + }) + benchmarkStress(b, s.stressCompress, 100) +} + +func BenchmarkStressEncrypt(b *testing.B) { + s := New(Config{ + Mode: ModeEncrypt, + Workers: 1, + IntensityMin: 100, + IntensityMax: 1000, + }) + benchmarkStress(b, s.stressEncrypt, 100) +} + +func BenchmarkStressSort(b *testing.B) { + s := New(Config{ + Mode: ModeSort, + Workers: 1, + IntensityMin: 100, + IntensityMax: 1000, + }) + benchmarkStress(b, s.stressSort, 1000) +} + +func BenchmarkStressBusy(b *testing.B) { + s := New(Config{ + Mode: ModeBusy, + Workers: 1, + IntensityMin: 100, + IntensityMax: 1000, + }) + benchmarkStress(b, s.stressBusy, 100) +} -- cgit v1.2.3