Add test of the list.
This commit is contained in:
1 parent
5a895d785c
commit
cc4fea3d68
2 files changed
+35
No files matched your search
@@ -104,6 +104,7 @@ bench-collectionc:
|
|||||||
|
|
||||||
bench-collectionc0:
|
bench-collectionc0:
|
||||||
$(CC) $(CFLAGS) $(CPPFLAGS) -I "$${COLLECTIONC}/include" -L "$${COLLECTIONC}" -static bench-collectionc.c -lcollectc -o bench-collectionc.exe
|
$(CC) $(CFLAGS) $(CPPFLAGS) -I "$${COLLECTIONC}/include" -L "$${COLLECTIONC}" -static bench-collectionc.c -lcollectc -o bench-collectionc.exe
|
||||||
|
@./bench-collectionc.exe 10
|
||||||
@./bench-collectionc.exe 20
|
@./bench-collectionc.exe 20
|
||||||
|
|
||||||
bench-plain:
|
bench-plain:
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
#include "array.h"
|
#include "array.h"
|
||||||
|
#include "slist.h"
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
@@ -44,12 +45,45 @@ static void test_array(size_t n)
|
|||||||
array_destroy(a2);
|
array_destroy(a2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/********************************************************************************************/
|
||||||
|
|
||||||
|
static void test_list(size_t n)
|
||||||
|
{
|
||||||
|
SList *a1, *a2;
|
||||||
|
enum cc_stat stat;
|
||||||
|
|
||||||
|
stat = slist_new(&a1);
|
||||||
|
if (stat != CC_OK) abort();
|
||||||
|
stat = slist_new(&a2);
|
||||||
|
if (stat != CC_OK) abort();
|
||||||
|
|
||||||
|
for(size_t i = 0; i < n; i++) {
|
||||||
|
stat = slist_add(a1, (void*) (uintptr_t)rand_get() );
|
||||||
|
if (stat != CC_OK) abort();
|
||||||
|
stat = slist_add(a2, (void*) (uintptr_t)rand_get() );
|
||||||
|
if (stat != CC_OK) abort();
|
||||||
|
}
|
||||||
|
unsigned int s = 0;
|
||||||
|
SListIter iter1, iter2;
|
||||||
|
void *e, *f;
|
||||||
|
slist_iter_init(&iter1, a1);
|
||||||
|
slist_iter_init(&iter2, a2);
|
||||||
|
while (slist_iter_next(&iter1, &e) == CC_OK && slist_iter_next(&iter2, &f) == CC_OK) {
|
||||||
|
s += ((unsigned int)(uintptr_t) e) * ((unsigned int)(uintptr_t) f);
|
||||||
|
}
|
||||||
|
g_result = s;
|
||||||
|
|
||||||
|
slist_destroy(a1);
|
||||||
|
slist_destroy(a2);
|
||||||
|
}
|
||||||
|
|
||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
|
|
||||||
int main(int argc, const char *argv[])
|
int main(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
int n = (argc > 1) ? atoi(argv[1]) : 0;
|
int n = (argc > 1) ? atoi(argv[1]) : 0;
|
||||||
|
if (n == 10)
|
||||||
|
test_function("List time",10000000, test_list);
|
||||||
if (n == 20)
|
if (n == 20)
|
||||||
test_function("Array time", 100000000, test_array);
|
test_function("Array time", 100000000, test_array);
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|||||||
Reference in new issue
Block a user