#!/bin/bash

set -eux

elisp_benchmarks=~/.emacs.d/elpa/elisp-benchmarks-1.1/elisp-benchmarks.el
gccemacs=~/Downloads/sources/emacs-meta/feature/native-comp/src/emacs

for i in {0..3}
do
    sudo swapoff -a
    sudo swapon -a

    (
        cd $(dirname ${elisp_benchmarks})/benchmarks
        ln -sf fibn-${i}.eln fibn.eln
    )

    ${gccemacs} -Q -batch -l ${elisp_benchmarks}            \
                -eval '(elisp-benchmarks-run "fibn\\.")' &

    out=fibn-${i}.log

    set +x
    while true
    do
        date +"%F-%T" >> ${out}
        ps o cputimes=,vsz=,rss=,args= $! >> ${out} || break
        free >> ${out}
        echo >> ${out}

        sleep 5
    done
    set -x
done
