#!/bin/bash

# Test the impact of flushing on write performance

echo "Testing write performance with different flush strategies..."

# Test 1: Write with flush after every line (simulating current behavior)
echo -e "\n1. Writing 100,000 lines WITH flush after each line:"
time (
    for i in {1..100000}; do
        echo "Line $i" >> /tmp/flush_test.txt
        sync
    done
)
rm -f /tmp/flush_test.txt

# Test 2: Write without explicit flushing
echo -e "\n2. Writing 100,000 lines WITHOUT flush:"
time (
    for i in {1..100000}; do
        echo "Line $i"
    done > /tmp/noflush_test.txt
)
FILE_SIZE=$(du -h /tmp/noflush_test.txt | cut -f1)
echo "File size: $FILE_SIZE"
rm -f /tmp/noflush_test.txt

echo -e "\nThe difference shows the impact of frequent flushing!"