aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-04-26 18:10:20 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-04-26 18:10:20 -0700
commitbff972ea91f40482c2abb28d9ad1d1a6fe285615 (patch)
treedb85a1693ec1ca8b7908071b664bab79af92b5f8 /sys
parentec21325b36adc7f52179ea010ff7bb19d121a6c1 (diff)
sys/libn/sort.c
Diffstat (limited to 'sys')
-rw-r--r--sys/libn/test.c67
1 files changed, 65 insertions, 2 deletions
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 <u.h>
#include <libn.h>
+#include <time.h>
+
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");
+ }
}