#!/usr/bin/env bash

set -o errexit
set -o pipefail
set -o nounset

BENCH_FUNC="codeobj_imports"
BENCH_EXPR="deque($BENCH_FUNC(co), maxlen=0)"
BIG_MODULE_PATH="$(dirname -- "$0")/data/big_module.py"
IMPORTS="from collections import deque; from mitogen.imports import $BENCH_FUNC"
COMPILE="co=compile(open('$BIG_MODULE_PATH').read(), '$BIG_MODULE_PATH', 'exec')"
PYTHONS=(
    python2.7 python3.{9..14}
)
for p in "${PYTHONS[@]}"; do
    echo -e -n "$BENCH_FUNC $p  "
    $p -m timeit -s "$IMPORTS" -s "$COMPILE" "$BENCH_EXPR"
done
