Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"fmt"
"log"
"os"
"runtime"
"runtime/metrics"
"sort"
Expand Down Expand Up @@ -117,8 +118,11 @@ func (b *ESDKBenchmark) runThroughputTest(dataSize int, iterations int) (*Benchm
endToEndLatencies = append(endToEndLatencies, iterationDuration)
totalBytes += int64(dataSize)

os.Stdout.Sync()
bar.Add(1)
fmt.Println()
}
fmt.Println()
totalDuration := time.Since(startTime).Seconds()

// Calculate metrics
Expand Down Expand Up @@ -199,6 +203,12 @@ func (b *ESDKBenchmark) runMemoryTest(dataSize int) (*BenchmarkResult, error) {
var peakHeap, peakAllocations float64
var avgHeapValues []float64

bar := progressbar.NewOptions(MemoryTestIterations,
progressbar.OptionSetDescription("Memory test"),
progressbar.OptionShowCount(),
progressbar.OptionSetWidth(50),
)

// Run iterations
for i := 0; i < MemoryTestIterations; i++ {
runtime.GC()
Expand Down Expand Up @@ -261,9 +271,14 @@ func (b *ESDKBenchmark) runMemoryTest(dataSize int) (*BenchmarkResult, error) {
}
avgHeapValues = append(avgHeapValues, iterAvgHeap)

log.Printf("=== Iteration %d === Peak Heap: %.2f MB, Total Allocs: %.2f MB, Avg Heap: %.2f MB (%v, %d samples)",
log.Printf("=== Iteration %d === Peak Heap: %.2f MB, Total Allocs: %.2f MB, Avg Heap: %.2f MB (%v, %d samples)\n",
i+1, iterPeakHeap, iterTotalAllocs, iterAvgHeap, operationDuration, len(continuousSamples))

os.Stdout.Sync()
bar.Add(1)
fmt.Println()
}
fmt.Println()

if len(avgHeapValues) == 0 {
return nil, fmt.Errorf("all memory test iterations failed")
Expand Down Expand Up @@ -307,6 +322,13 @@ func (b *ESDKBenchmark) runConcurrentTest(dataSize int, concurrency int, iterati
var timesMutex sync.Mutex
var wg sync.WaitGroup

totalOps := concurrency * iterationsPerWorker
bar := progressbar.NewOptions(totalOps,
progressbar.OptionSetDescription("Concurrent test"),
progressbar.OptionShowCount(),
progressbar.OptionSetWidth(50),
)

errorChan := make(chan error, concurrency)
startTime := time.Now()

Expand All @@ -325,6 +347,9 @@ func (b *ESDKBenchmark) runConcurrentTest(dataSize int, concurrency int, iterati
return
}
workerTimes = append(workerTimes, time.Since(iterStart).Seconds()*1000)
os.Stdout.Sync()
bar.Add(1)
fmt.Println()
}

timesMutex.Lock()
Expand All @@ -334,6 +359,7 @@ func (b *ESDKBenchmark) runConcurrentTest(dataSize int, concurrency int, iterati
}

wg.Wait()
fmt.Println()
totalDuration := time.Since(startTime).Seconds()

// Check for errors
Expand All @@ -344,7 +370,6 @@ func (b *ESDKBenchmark) runConcurrentTest(dataSize int, concurrency int, iterati
}

// Calculate metrics
totalOps := concurrency * iterationsPerWorker
totalBytes := int64(totalOps * dataSize)

sort.Float64s(allTimes)
Expand Down Expand Up @@ -374,46 +399,52 @@ func (b *ESDKBenchmark) runConcurrentTest(dataSize int, concurrency int, iterati
// === Test Orchestration ===

// runThroughputTests executes all throughput tests
func (b *ESDKBenchmark) runThroughputTests(dataSizes []int, iterations int) {
func (b *ESDKBenchmark) runThroughputTests(dataSizes []int, iterations int, overallBar *progressbar.ProgressBar) {
log.Println("Running throughput tests...")
for _, dataSize := range dataSizes {
result, err := b.runThroughputTest(dataSize, iterations)
if err != nil {
log.Printf("Throughput test failed: %v", err)
continue
} else {
b.Results = append(b.Results, *result)
log.Printf("Throughput test completed: %.2f ops/sec", result.OpsPerSecond)
}
b.Results = append(b.Results, *result)
log.Printf("Throughput test completed: %.2f ops/sec", result.OpsPerSecond)
os.Stdout.Sync()
overallBar.Add(1)
}
}

// runMemoryTests executes all memory tests
func (b *ESDKBenchmark) runMemoryTests(dataSizes []int) {
func (b *ESDKBenchmark) runMemoryTests(dataSizes []int, overallBar *progressbar.ProgressBar) {
log.Println("Running memory tests...")
for _, dataSize := range dataSizes {
result, err := b.runMemoryTest(dataSize)
if err != nil {
log.Printf("Memory test failed: %v", err)
continue
} else {
b.Results = append(b.Results, *result)
log.Printf("Memory test completed: %.2f MB peak", result.PeakMemoryMB)
}
b.Results = append(b.Results, *result)
log.Printf("Memory test completed: %.2f MB peak", result.PeakMemoryMB)
os.Stdout.Sync()
overallBar.Add(1)
}
}

// runConcurrencyTests executes all concurrency tests
func (b *ESDKBenchmark) runConcurrencyTests(dataSizes []int, concurrencyLevels []int) {
func (b *ESDKBenchmark) runConcurrencyTests(dataSizes []int, concurrencyLevels []int, overallBar *progressbar.ProgressBar) {
log.Println("Running concurrency tests...")
for _, dataSize := range dataSizes {
for _, concurrency := range concurrencyLevels {
if concurrency > 1 { // Skip single-threaded
result, err := b.runConcurrentTest(dataSize, concurrency, 5)
if err != nil {
log.Printf("Concurrent test failed: %v", err)
continue
} else {
b.Results = append(b.Results, *result)
log.Printf("Concurrent test completed: %.2f ops/sec @ %d threads", result.OpsPerSecond, concurrency)
}
b.Results = append(b.Results, *result)
log.Printf("Concurrent test completed: %.2f ops/sec @ %d threads", result.OpsPerSecond, concurrency)
os.Stdout.Sync()
overallBar.Add(1)
}
}
}
Expand All @@ -429,21 +460,45 @@ func (b *ESDKBenchmark) RunAllBenchmarks() error {
dataSizes = append(dataSizes, sizes...)
}

// Calculate total tests for progress tracking
totalTests := 0
if b.shouldRunTestType("throughput") {
totalTests += len(dataSizes)
}
if b.shouldRunTestType("memory") {
totalTests += len(dataSizes)
}
if b.shouldRunTestType("concurrency") {
for range dataSizes {
for _, concurrency := range b.Config.ConcurrencyLevels {
if concurrency > 1 {
totalTests++
}
}
}
}

overallBar := progressbar.NewOptions(totalTests,
progressbar.OptionSetDescription("Overall progress"),
progressbar.OptionShowCount(),
progressbar.OptionSetWidth(50),
)

// Run test suites
if b.shouldRunTestType("throughput") {
b.runThroughputTests(dataSizes, b.Config.Iterations.Measurement)
b.runThroughputTests(dataSizes, b.Config.Iterations.Measurement, overallBar)
} else {
log.Println("Skipping throughput tests (not in test_types)")
}

if b.shouldRunTestType("memory") {
b.runMemoryTests(dataSizes)
b.runMemoryTests(dataSizes, overallBar)
} else {
log.Println("Skipping memory tests (not in test_types)")
}

if b.shouldRunTestType("concurrency") {
b.runConcurrencyTests(dataSizes, b.Config.ConcurrencyLevels)
b.runConcurrencyTests(dataSizes, b.Config.ConcurrencyLevels, overallBar)
} else {
log.Println("Skipping concurrency tests (not in test_types)")
}
Expand Down
Loading
Loading