#!/usr/bin/env bash NPROC=$(grep -c ^processor /proc/cpuinfo) RESULTS_FOLDER=$(mktemp --dir) # Checking ulimit if [[ $(ulimit) == "unlimited" ]];then ULIMIT_YES="no" while [[ $ULIMIT_YES == "no" ]] do read -p "ulimit is unlimited. This may not go well for the system. Are you sure? (yes/no): " ULIMIT_YES if [[ $ULIMIT_YES == "yes" ]];then break elif [[ $ULIMIT_YES == "no" ]];then exit fi done fi # Run the job with n number of nprocs find ./jobs -type f -name "*.sh" | \ while read JOB_NAME do printf "Starting on job $JOB_NAME...\n" SCALE=1 CURRENT=9998 BEFORE=9999 RESULT_FILE="$RESULTS_FOLDER/$(basename $JOB_NAME)" #printf "Result file: $(readlink -f $RESULT_FILE)\n" # Keep scaling up until the runtime is slower than the previous result while [[ $(echo "$CURRENT < $BEFORE" | bc) -eq 1 ]] do BEFORE=$CURRENT PARALLEL=$(( $NPROC * $SCALE )) CURRENT=$( \ /bin/time --format "%e" \ bash -c "seq 1 10000000 | xargs -P $PARALLEL bash $JOB_NAME >/dev/null 2>&1" 2>&1 | \ tee -a $RESULT_FILE \ ) (( SCALE++ )) done # Display the results printf "nproc\tseconds\n" awk \ -v nproc="$NPROC" \ '{print NR*nproc, "\t", $0}' \ $RESULTS_FOLDER/* done # Clean up rm -rf $RESULTS_FOLDER