changeset 776:572bf6ccdd3f

Script to test the performance/runtime of some sort implementations for a bunch of randon unsorted arrays of differenz sizes
author Franz Glasner <fzglas.hg@dom66.de>
date Thu, 24 Oct 2024 11:36:18 +0200
parents ff36742b9955
children 3f9b22ddacb8
files tests/sort-perf/sort-perf.sh
diffstat 1 files changed, 77 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/sort-perf/sort-perf.sh	Thu Oct 24 11:36:18 2024 +0200
@@ -0,0 +1,77 @@
+#!/bin/sh
+#:
+#: Measure the performance of implemented array sort methods.
+#:
+
+set -u
+
+export PERFDIR="$(dirname "$0")"
+export TESTDIR="${PERFDIR}/.."
+. "${TESTDIR}/testsetup.sh"
+_p_datadir="${TESTDIR}/../share/local-bsdtools"
+. "${_p_datadir}/farray.sh"
+
+
+get_ts() {
+    /usr/bin/ntpq -c "rv 0 clock" localhost
+}
+
+
+#:
+#: Run all tests with the same random array
+#:
+#: Args:
+#:   $1 (int): The length of the randon array to use to
+#:
+test_for() {
+    # $1
+
+    local UNSORTED TEST
+
+    echo "Testing for an array with length ${1}"
+
+    create_random_array UNSORTED "${1}"
+
+    if [ "${1}" -le 2000 ]; then
+	farray_create TEST
+	farray_splice "" TEST 1 "" UNSORTED
+	echo "===> Gnome Sort with ${1} items"
+	get_ts
+	farray_gnomesort TEST
+	get_ts
+	farray_release TEST
+    else
+	echo "===> SKIPPED: Gnome Sort with ${1} items"
+    fi
+
+    if [ "${1}" -le 20000 ]; then
+	farray_create TEST
+	farray_splice "" TEST 1 "" UNSORTED
+	echo "===> Shell Sort with ${1} items"
+	get_ts
+	farray_shellsort TEST
+	get_ts
+	farray_release TEST
+    else
+	echo "===> SKIPPED: Shell Sort with ${1} items"
+    fi
+
+    farray_release UNSORTED
+}
+
+
+test_for 2
+test_for 3
+test_for 4
+test_for 5
+test_for 10
+test_for 20
+test_for 50
+test_for 100
+test_for 500
+test_for 1000
+test_for 2000
+test_for 5000
+test_for 10000
+test_for 20000
+test_for 50000