#!/bin/bash
n=${1:-1000000}
command -v bc >/dev/null 2>&1 || { echo "bc is required"; exit 1; }

bench() {
  printf 'scale=10\na=1.2345678901\nb=1.2345678901\nfor(i=0;i<%s;i++) x=a*b\n' "$n" | bc >/dev/null
}

start=$(date +%s.%N)
bench
end=$(date +%s.%N)

dur=$(echo "$end - $start" | bc -l)
flops=$(echo "$n / $dur" | bc -l)

printf "iterations=%s\ntime_s=%s\nFLOPS=%s\n" "$n" "$dur" "$flops"

