<commit_before>#!/usr/bin/env bash

set -e

SELF=${0%/*}
BOOSTCACHED=${1:-"$SELF/../.cmake/boostcached"}
BC_BENCHMARK=${2:-"$SELF/../src/benchmark/bc-benchmark"}
ONE_CONN_BENCHMARK=${3:-"$SELF/one_conn_awk_bench.sh"}
SOCKET=${4:-"$SELF/../.cmake/boostcached.sock"}

#
# Helper function
#

function indent()
{
    $1 | awk '{if ($0 == "") { exit; } print "\t" $0}'
}

function get_machine_info()
{
    echo "CPU info"

    if $( which lscpu &>/dev/null ); then
        indent "lscpu"
    else
        indent "cat /proc/cpuinfo"
    fi
}

# Start server, run benchmark, and kill server
#
# @param server
# @param benchmark
#
run_benchmark()
{
    echo "Starting server '$1'"
    eval "$1 &"
    SERVER_PID="$!"
    trap "echo Killing server; ps u $SERVER_PID &> /dev/null && kill $SERVER_PID" EXIT
    sleep 2
    echo "Starting benchmark '$2'"
    $2
    kill $SERVER_PID
}

#
# Some information
#
get_machine_info<commit_msg>[utils] run_benchmarks: highlight starting of benchmark<commit_after>#!/usr/bin/env bash

set -e

SELF=${0%/*}
BOOSTCACHED=${1:-"$SELF/../.cmake/boostcached"}
BC_BENCHMARK=${2:-"$SELF/../src/benchmark/bc-benchmark"}
ONE_CONN_BENCHMARK=${3:-"$SELF/one_conn_awk_bench.sh"}
SOCKET=${4:-"$SELF/../.cmake/boostcached.sock"}

#
# Helper function
#

function indent()
{
    $1 | awk '{if ($0 == "") { exit; } print "\t" $0}'
}

function get_machine_info()
{
    echo "CPU info"

    if $( which lscpu &>/dev/null ); then
        indent "lscpu"
    else
        indent "cat /proc/cpuinfo"
    fi
}

# Start server, run benchmark, and kill server
#
# @param server
# @param benchmark
#
run_benchmark()
{
    echo "*********************************************"
    echo "* Starting server '$1'"

    eval "$1 &"
    SERVER_PID="$!"
    trap "echo Killing server; ps u $SERVER_PID &> /dev/null && kill $SERVER_PID" EXIT
    sleep 2

    echo "* Starting benchmark '$2'"
    echo "*********************************************"

    $2
    kill $SERVER_PID
}

#
# Some information
#
get_machine_info
{'fraction_non_alphanumeric': 0.2170889220069548, 'fraction_numerical': 0.012916045702930949, 'mean_word_length': 3.349892008639309, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '778060', 'n_tokens_mistral': 770, 'n_tokens_neox': 738, 'n_words': 166}