Merge dependabot/npm_and_yarn/examples/typescript/websocket-server-pool/ws-worker_thr...
[poolifier.git] / benchmarks / versus-external-pools / bench.sh
1 #!/usr/bin/env bash
2
3 usage() {
4 echo "Usage: $0 [-s <pool size> -i <number of iterations> -t <CPU_INTENSIVE|IO_INTENSIVE>] [-n <number of tasks>]" 1>&2
5 exit 1
6 }
7
8 while getopts "s:i:t:n:h" option
9 do
10 case "${option}" in
11 s)
12 poolSize=${OPTARG}
13 ;;
14 i)
15 iterations=${OPTARG}
16 ;;
17 t)
18 taskType=${OPTARG}
19 ;;
20 n)
21 taskSize=${OPTARG}
22 ;;
23 :)
24 echo "Error: Missing option argument for '-${OPTARG}'" >&2;
25 usage
26 ;;
27 \?)
28 # Invalid option
29 echo "Error: Unknown or invalid option for '-${OPTARG}'" >&2;
30 usage
31 ;;
32 *|h)
33 usage
34 ;;
35 esac
36 done
37
38 taskType=${taskType:-'CPU_INTENSIVE'}
39 taskSize=${taskSize:-5000}
40 poolSize=${poolSize:-$(nproc --all)}
41 iterations=${iterations:-100000}
42
43 echo 'Running benchmarks with pool size:' ${poolSize}', number of iterations:' ${iterations}', task type:' ${taskType} 'and task size:' ${taskSize}
44 export NODE_ENV=production
45 export TASK_TYPE=${taskType}
46 export TASK_SIZE=${taskSize}
47 export POOL_SIZE=${poolSize}
48 export NUM_ITERATIONS=${iterations}
49 case "$OSTYPE" in
50 darwin*)
51 caffeinate ./hyperfine_benchmarks.sh
52 ;;
53 linux*)
54 systemd-inhibit --what=idle ./hyperfine_benchmarks.sh
55 ;;
56 *)
57 echo "Unsupported $OSTYPE"
58 ;;
59 esac