#!/bin/bash shopt -s nocasematch ## Regex is not case sensitive LC_NUMERIC="C" ## Set POSIX locale for math ## Settings VERSION="1.1" WORKDIR="benchmark" SRC="QFT" RUNPDFLATEX="pdflatex -interaction=nonstopmode -halt-on-error $SRC.tex" RUNBIBTEX="bibtex $SRC.aux" RUNS=3 API="https://web.itp3.uni-stuttgart.de/latex-benchmark/submit.php" ## Colors YELLOW='\033[1;33m' GREEN='\033[0;32m' RED='\033[0;31m' NC='\033[0m' ## Compile data to post with curl function generate_post_data() { cat < /dev/null; then echo -e "${RED}→ pdfTeX NOT installed! Aborting ...${NC}" echo exit 1 fi LVERSION=$(pdflatex --version | head -1) echo -e "→ pdfTeX found:\t$LVERSION" ## BibTex if ! command -v bibtex &> /dev/null; then echo -e "${RED}→ BibTex NOT installed! Aborting ...${NC}" echo exit 1 fi BVERSION=$(bibtex --version | head -1); echo -e "→ BibTex found:\t$BVERSION" ## ********************************************** echo echo -e "${GREEN}Collecting data:${NC}" echo -e "→ Version:\t$VERSION" case "${SYSTEM}" in Linux*) HOST=$( Second run if [[ "$ret" =~ "latex warning" ]]; then echo -n -e "→ Running BibTeX ... \t\t\t\t" if ret=$($RUNBIBTEX); then echo -e "${GREEN}[OK]${NC}" else echo -e "${RED}[FAILED]${NC}" echo echo -e "${RED}BibTeX did throw an error. Aborting ...${NC}" echo exit 1 fi echo -n -e "→ Running PDFLaTeX for the second time ... \t" ret=$($RUNPDFLATEX) echo -e "${GREEN}[OK]${NC}" fi ## Warnings? -> Third run if [[ "$ret" =~ "latex warning" ]]; then echo -n -e "→ Running PDFLaTeX for the third time ... \t" if RET=$($RUNPDFLATEX); then if [[ "$RET" =~ "latex warning" ]]; then echo -e "${YELLOW}[OK?]${NC}" echo -e "${YELLOW}The second run reported warnings. This is unusual ...${NC}" else echo -e "${GREEN}[OK]${NC}" fi else echo -e "${RED}[FAILED]${NC}" echo echo -e "${RED}PDFLatex could not compile the benchmark document.${NC}" echo -e "${RED}Maybe you are missing packages?${NC}" echo -e "${RED}Aborting ...${NC}" echo exit 1 fi fi ## ----------------------------------------------------------------------------- ## RUN BENCHMARK echo echo -e "${GREEN}Running benchmark:${NC}" ## ----------------------------------------------------------------------------- T=() for (( i=1; i<=$RUNS; i++ )); do echo -n "→ RUN $i ... " t=$(TIMEFORMAT=%1R; { time $RUNPDFLATEX > /dev/null; } 2>&1 | sed 's/,/\./') echo -e "T = ${YELLOW}${t}${NC} s" T+=($t) done ## ----------------------------------------------------------------------------- ## RESULT ## ----------------------------------------------------------------------------- ## Average sum=$(IFS="+"; bc -l -q <<< "${T[*]}") len=${#T[@]} avg=$(bc -l -q <<< "$sum/$len") ## Min/Max max="${T[0]}" min="${T[0]}" for t in "${T[@]}"; do max=$(bc -l -q <<< "if($t>$max) $t else $max") min=$(bc -l -q <<< "if($t<$min) $t else $min") done ## Format printf -v avg '%.1f' "$avg" printf -v max '%.1f' "$max" printf -v min '%.1f' "$min" printf -v INFO "%-102s" "AVG = ${YELLOW}$avg${NC} s | MIN = ${GREEN}$min${NC} s | MAX = ${RED}$max${NC} s" echo echo -e "┏━━━━━━━━━━━━━━━━━━━━━━ ${YELLOW}RESULTS${NC} ━━━━━━━━━━━━━━━━━━━━━━┓" echo -e "┃ ${INFO} ┃" echo -e "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛" ## ----------------------------------------------------------------------------- ## UPLOAD ## ----------------------------------------------------------------------------- COMMENT="" KEY="" echo read -p "→ Enter key to submit score to database (leave empty to skip): " KEY if [[ $KEY ]]; then read -p "→ Comment (max 200 characters): " COMMENT upload fi # while true; do # read -p "Do you want to upload your score to the database? [y/n]" yn # case $yn in # [Yy]* ) upload; break;; # [Nn]* ) break;; # * ) echo "Please answer yes or no.";; # esac # done echo echo "Done!"