Apply dependencies update
[poolifier.git] / benchmarks / versus-external-pools / bench.sh
index 05c156c92b27d774f56e742b19e1df7fe81e916e..7a1bb6c0e261fe4095f2dad1b229ac4742ca9e2e 100755 (executable)
@@ -1,37 +1,55 @@
-export NODE_ENV=production
+#!/usr/bin/env bash
 
-# Execute bench
-# export POOL_SIZE=8
-# export NUM_ITERATIONS=10000
-# hyperfine --export-markdown BENCH-10000.MD --min-runs 10 \
-#   'node dynamic-poolifier.js' \
-#   'node dynamic-suchmokuo-node-worker-threads-pool.js' \
-#   'node fixed-poolifier.js' \
-#   'node static-suchmokuo-node-worker-threads-pool.js' \
-#   'node piscina.js'
+### The -t argument permit to specify the type of task that you want to benchmark.
+### Supported values are CPU_INTENSIVE, IO_INTENSIVE
+### The -s argument permit to specify the size of task that you want to benchmark.
 
-# echo "Sleeping...."
-# sleep 60
+usage() {
+    echo "Usage: $0 [-t <CPU_INTENSIVE|IO_INTENSIVE>] [-s <number of tasks>]" 1>&2
+    exit 1
+}
 
+taskType='CPU_INTENSIVE'
+taskSize=5000
+while getopts "t:s:h" option
+do
+  case "${option}" in
+    t)
+      taskType=${OPTARG}
+      ;;
+    s)
+      taskSize=${OPTARG}
+      ;;
+    :)
+      echo "Error: Missing option argument for '-${OPTARG}'" >&2;
+      usage
+      ;;
+    \?)
+      # Invalid option
+      echo "Error: Unknown or invalid option for '-${OPTARG}'" >&2;
+      usage
+      ;;
+    *|h)
+      usage
+      ;;
+  esac
+done
+
+echo 'Running benchmarks for task type:' ${taskType} 'and task size:' ${taskSize}
+export TASK_TYPE=${taskType}
+export TASK_SIZE=${taskSize}
+# Execute bench
+export NODE_ENV=production
 export POOL_SIZE=10
 export NUM_ITERATIONS=100000
-hyperfine --export-markdown BENCH-100000.MD --min-runs 10 \
-  'node static-suchmokuo-node-worker-threads-pool.js' \
-  'node dynamic-poolifier.js' \
-  'node piscina.js'
-
-# export POOL_SIZE=8
-# export NUM_ITERATIONS=50000
-# hyperfine --export-markdown BENCH-50000.MD --min-runs 10 \
-#   'node dynamic-poolifier.js' \
-#   'node dynamic-suchmokuo-node-worker-threads-pool.js' \
-#   'node fixed-poolifier.js' \
-#   'node static-suchmokuo-node-worker-threads-pool.js' \
-#   'node piscina.js'
-
-# export NUM_ITERATIONS=100000
-#   hyperfine --export-markdown BENCH-50000.MD --min-runs 20 \
-#     'node dynamic-poolifier.js' \
-#     'node static-suchmokuo-node-worker-threads-pool.js' \
-#     'node piscina.js'
-
+case "$OSTYPE" in
+  darwin*)
+    caffeinate ./hyperfine_benchmarks.sh
+    ;;
+  linux*)
+    systemd-inhibit ./hyperfine_benchmarks.sh
+    ;;
+  *)
+    echo "Unsupported $OSTYPE"
+    ;;
+esac