hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit f7ccc2ff0fb67c15925fb8de15f8439fe0582401
parent 6a7563fc01cea51f96914a72db7c7a01544bcdeb
Author: Alexey Yerin <yyp@disroot.org>
Date:   Wed,  6 Sep 2023 21:33:02 +0300

sort: Add performance tests for powersort

Signed-off-by: Alexey Yerin <yyp@disroot.org>

Diffstat:
Mscripts/gen-stdlib | 3++-
Msort/+test.ha | 25+++++++++++++++++++++++++
Mstdlib.mk | 2+-
3 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/scripts/gen-stdlib b/scripts/gen-stdlib @@ -1349,11 +1349,12 @@ sort() { if [ $testing -eq 0 ] then gensrcs_sort + gen_ssa sort math strings types else gensrcs_sort \ +test.ha + gen_ssa sort math math::random strings types fi - gen_ssa sort math strings types } strconv() { diff --git a/sort/+test.ha b/sort/+test.ha @@ -1,6 +1,8 @@ // License: MPL-2.0 // (c) 2021 Drew DeVault <sir@cmpwn.com> // (c) 2021 Ember Sawady <ecs@d2evs.net> + +use math::random; use types; @test fn lbisect() void = { @@ -60,7 +62,30 @@ use types; for (let i = 1z; i < len(nums); i += 1) { assert(nums[i] >= nums[i - 1]); }; +}; + +@test fn big_equal() void = { + let nums = alloc([42...], 1000000); + defer free(nums); + sort(nums, size(int), &icmp); + for (let i = 0z; i < len(nums); i += 1) { + assert(nums[i] == 42); + }; +}; + +@test fn big_random() void = { + let nums = alloc([0...], 100000); + defer free(nums); + let rand = random::init(0x424242); + for (let i = 0z; i < len(nums); i += 1) { + nums[i] = random::next(&rand): int; + }; + + sort(nums, size(int), &icmp); + for (let i = 1z; i < len(nums); i += 1) { + assert(nums[i] >= nums[i - 1]); + }; }; @test fn sorted() void = { diff --git a/stdlib.mk b/stdlib.mk @@ -4566,7 +4566,7 @@ testlib_sort_any_srcs = \ $(STDLIB)/sort/types.ha \ $(STDLIB)/sort/+test.ha -$(TESTCACHE)/sort/sort-any.ssa: $(testlib_sort_any_srcs) $(testlib_rt) $(testlib_math_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_types_$(PLATFORM)) +$(TESTCACHE)/sort/sort-any.ssa: $(testlib_sort_any_srcs) $(testlib_rt) $(testlib_math_$(PLATFORM)) $(testlib_math_random_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_types_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(TESTCACHE)/sort @$(testlib_env) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nsort \