#!/bin/bash

# Memory benchmark script for wasot random command
# Generates CSV with memory usage at different line counts

OUTPUT_FILE="memory_benchmark_fixed.csv"

echo "Running memory benchmark from 1000 to 400000 lines..."
echo "Results will be saved to $OUTPUT_FILE"

# Create CSV header
echo "lines,memory_mb" > "$OUTPUT_FILE"

# Generate 20 data points from 1000 to 400000
# Using logarithmic spacing for better coverage
for i in {1..20}; do
    # Calculate line count using logarithmic spacing
    lines=$(python3 -c "import math; print(int(1000 * (400)**(($i-1)/19)))")
    
    echo "Testing with $lines lines..."
    
    # Run memory measurement and extract just the number
    memory_mb=$(./scripts/measure_memory.sh "$lines" | tail -n1 | cut -d' ' -f1)
    
    # Add to CSV
    echo "$lines,$memory_mb" >> "$OUTPUT_FILE"
    
    echo "  -> $memory_mb MB"
done

echo ""
echo "Benchmark complete! Results saved to $OUTPUT_FILE"
echo ""
echo "Summary:"
cat "$OUTPUT_FILE"