1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#include <u.h>
#include <base.h>
#include <base/macro/map.h>
#include <time.h>
int
less(void* a, void* b)
{
int ai, bi;
ai = *(int*)a;
bi = *(int*)b;
return ai - bi;
}
int
test·sort()
{
clock_t t;
int i, test[10000];
for (i = 0; i < arrlen(test); i++) {
test[i] = rand();
}
t = clock();
sort·int(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), (int (*)(const void *, const void *))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;
}
int
main()
{
int err;
#if 0
if (err = test·coro(), err) {
errorf("test fail: coroutine");
}
#endif
if (err = test·sort(), err) {
errorf("test fail: coroutine");
}
return 0;
}
|