From bff972ea91f40482c2abb28d9ad1d1a6fe285615 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Sun, 26 Apr 2020 18:10:20 -0700 Subject: sys/libn/sort.c --- sys/libn/test.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) (limited to 'sys') diff --git a/sys/libn/test.c b/sys/libn/test.c index 3f97453..5ee230f 100644 --- a/sys/libn/test.c +++ b/sys/libn/test.c @@ -1,6 +1,8 @@ #include #include +#include + uintptr printtest(Coro *c, uintptr d) { @@ -51,8 +53,8 @@ filter(Coro *c, uintptr data) return 0; } -int -main() +error +test·coro() { int i; Coro *c[4]; @@ -103,4 +105,65 @@ main() num = coro·yield(cur, (uintptr)&msg); printf("--> prime number %lu\n", num); } + return 0; +} + +int +less(void* a, void* b) +{ + int ai, bi; + ai = *(int*)a; + bi = *(int*)b; + + return ai - bi; +} + +error +test·sort() +{ + clock_t t; + int i, test[1000000]; + for (i = 0; i < arrlen(test); i++) { + test[i] = rand(); + } + + t = clock(); + sort·ints(arrlen(test), test); + t = clock() - t; + printf("inlined code took %f ms to execute\n", 1000.*t/CLOCKS_PER_SEC); + + for (i = 0; i < arrlen(test); i++) { + test[i] = rand(); + } + + t = clock(); + qsort(test, arrlen(test), sizeof(int), &less); + t = clock() - t; + printf("std qsort code took %f ms to execute\n", 1000.*t/CLOCKS_PER_SEC); + + /* + for (i = 1; i < arrlen(test); i++) { + if (test[i] >= test[i-1]) { + printf("%d is less that %d\n", test[i], test[i-1]); + } else { + printf("ERROR: %d is NOT less that %d\n", test[i], test[i-1]); + } + } + */ + + return 0; +} + +error +main() +{ + error err; +#if 0 + if (err = test·coro(), err) { + errorf("test fail: coroutine"); + } +#endif + if (err = test·sort(), err) { + errorf("test fail: coroutine"); + } } -- cgit v1.2.1