#!/bin/bash

printf "%s\n" "Libc:"

size=1
for i in $(seq 0 20); do

    # clear cache
    sync; echo 3 > /proc/sys/vm/drop_caches
    printf "buffer size: %s - " "$size"

    output=$({ time ./hello-clang libc "$size" < datafile > /dev/null; } 2>&1)
    value_output=$?

    if [[ $value_output -eq 1 ]]; then
        echo "$output" | grep real | awk '{ print $2 }'
    #else
    #    printf "%s\n" "error"
    #    break
    fi

    let size=size*2
done

size=1
printf "%s\n" "Syscalls:"
for i in $(seq 0 20); do

    # clear cache
    sync; echo 3 > /proc/sys/vm/drop_caches
    printf "buffer size: %s - " "${size}"

    output=$({ time ./hello-clang syscall "${size}" < datafile > /dev/null; } 2>&1)
    value_output=$?

    # print only if the execution was successfull
    if [[ $value_output -eq 1 ]]; then
        echo "$output" | grep real | awk '{ print $2 }'
    #else
    #    printf "%s\n" "error"
    #    break
    fi

    let size=size*2
done

