# HG changeset patch # User Franz Glasner # Date 1729762578 -7200 # Node ID 572bf6ccdd3f95b4192d22a037fdf20250b4a82a # Parent ff36742b99550f7872968a0d751db6fdd66067a6 Script to test the performance/runtime of some sort implementations for a bunch of randon unsorted arrays of differenz sizes diff -r ff36742b9955 -r 572bf6ccdd3f tests/sort-perf/sort-perf.sh --- /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