Update benchmarks and examples
This commit is contained in:
1 parent
33c33e8947
commit
415720c6a6
5 files changed
+34
-42
No files matched your search
@@ -79,11 +79,11 @@ CMC_COLLECTION_GENERATE(MULTISET, ms, mset, /* K */, int)
|
||||
{ \
|
||||
printf("+------------------------------------------------------------ %10s\n", #NAME); \
|
||||
printf("+------------------------------------------------------------ \n"); \
|
||||
cmc_timer timer, total; \
|
||||
struct cmc_timer timer, total; \
|
||||
int r, k, v; \
|
||||
size_t j; \
|
||||
\
|
||||
sname *coll = initfunc; \
|
||||
struct sname *coll = initfunc; \
|
||||
\
|
||||
cmc_timer_start(total); \
|
||||
cmc_timer_start(timer); \
|
||||
@@ -118,7 +118,7 @@ CMC_COLLECTION_GENERATE(MULTISET, ms, mset, /* K */, int)
|
||||
\
|
||||
double search_time = timer.result; \
|
||||
\
|
||||
sname##_iter iter; \
|
||||
struct sname##_iter iter; \
|
||||
\
|
||||
cmc_timer_start(timer); \
|
||||
\
|
||||
@@ -221,7 +221,7 @@ int main(void)
|
||||
|
||||
// Linear containers have to search for NMIN elements and non-linear (hash
|
||||
// and tree) have to search for all elements.
|
||||
cmc_timer timer;
|
||||
struct cmc_timer timer;
|
||||
cmc_timer_start(timer);
|
||||
|
||||
DEQUE_io_benchmark(array, sarray, NMIN);
|
||||
|
||||
@@ -6,5 +6,3 @@ main:
|
||||
a.exe
|
||||
gcc queue.c -I $(INCLUDE) $(CFLAGS) -o a.exe -DSAC_QUEUE
|
||||
a.exe
|
||||
gcc queue.c -I $(INCLUDE) $(CFLAGS) -o a.exe -DEXT_QUEUE
|
||||
a.exe
|
||||
@@ -18,16 +18,12 @@
|
||||
|
||||
#if defined(CMC_QUEUE)
|
||||
#include "cmc/queue.h"
|
||||
QUEUE_GENERATE(q, queue, , int)
|
||||
CMC_GENERATE_QUEUE(q, queue, int)
|
||||
#define TARGET "QUEUE"
|
||||
#elif defined(SAC_QUEUE)
|
||||
#include "sac/queue.h"
|
||||
SAC_QUEUE_GENERATE(q, queue, , int, MAX)
|
||||
#define TARGET "SAC QUEUE"
|
||||
#elif defined(EXT_QUEUE)
|
||||
#include "ext/linkedqueue.h"
|
||||
LINKEDQUEUE_GENERATE(q, queue, , int)
|
||||
#define TARGET "LINKED QUEUE"
|
||||
#else
|
||||
#error Please define either CMC_QUEUE, SAC_QUEUE or EXT_QUEUE
|
||||
#endif
|
||||
@@ -36,19 +32,17 @@ int main(void)
|
||||
{
|
||||
|
||||
#if defined(CMC_QUEUE)
|
||||
queue *q = q_new(MAX);
|
||||
struct queue *q = q_new(MAX);
|
||||
#elif defined(SAC_QUEUE)
|
||||
queue _q = q_new();
|
||||
queue_ptr q = &_q;
|
||||
#elif defined(EXT_QUEUE)
|
||||
queue *q = q_new();
|
||||
#endif
|
||||
|
||||
size_t sum = 0;
|
||||
int i = 0;
|
||||
|
||||
timer_t timer;
|
||||
TIMER_START(timer);
|
||||
struct cmc_timer timer;
|
||||
cmc_timer_start(timer);
|
||||
|
||||
while (q_count(q) != MAX)
|
||||
{
|
||||
@@ -65,8 +59,8 @@ int main(void)
|
||||
|
||||
}
|
||||
|
||||
TIMER_STOP(timer);
|
||||
TIMER_CALC(timer);
|
||||
cmc_timer_stop(timer);
|
||||
cmc_timer_calc(timer);
|
||||
|
||||
printf("----------------------------------------\n");
|
||||
printf("%s\n", TARGET);
|
||||
@@ -74,8 +68,8 @@ int main(void)
|
||||
printf("SUM: %" PRIuMAX "\n", sum);
|
||||
printf("----------------------------------------\n");
|
||||
|
||||
#if defined(CMC_QUEUE) || defined(EXT_QUEUE)
|
||||
q_free(q);
|
||||
#if defined(CMC_QUEUE)
|
||||
q_free(q, NULL);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
||||
+8
-8
@@ -5,9 +5,9 @@ CMC_GENERATE_STACK(stk, stack, int)
|
||||
|
||||
struct
|
||||
{
|
||||
stack *from;
|
||||
stack *aux;
|
||||
stack *to;
|
||||
struct stack *from;
|
||||
struct stack *aux;
|
||||
struct stack *to;
|
||||
} print_aux = {NULL};
|
||||
|
||||
void print_stacks()
|
||||
@@ -27,14 +27,14 @@ void print_stacks()
|
||||
printf("+---+---+---+\n\n");
|
||||
}
|
||||
|
||||
void move(stack *from, stack *to)
|
||||
void move(struct stack *from, struct stack *to)
|
||||
{
|
||||
stk_push(to, stk_top(from));
|
||||
|
||||
stk_pop(from);
|
||||
}
|
||||
|
||||
void hanoi(int n, stack *from, stack *aux, stack *to)
|
||||
void hanoi(int n, struct stack *from, struct stack *aux, struct stack *to)
|
||||
{
|
||||
if (n == 0)
|
||||
return;
|
||||
@@ -50,9 +50,9 @@ void hanoi(int n, stack *from, stack *aux, stack *to)
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
stack *from = stk_new(10);
|
||||
stack *to = stk_new(10);
|
||||
stack *aux = stk_new(10);
|
||||
struct stack *from = stk_new(10);
|
||||
struct stack *to = stk_new(10);
|
||||
struct stack *aux = stk_new(10);
|
||||
|
||||
for (int i = 4; i >= 1; i--)
|
||||
stk_push(from, i);
|
||||
|
||||
+14
-14
@@ -8,20 +8,20 @@
|
||||
#define DOC_MARGIN 4
|
||||
|
||||
CMC_GENERATE_LIST(row, row, char)
|
||||
CMC_GENERATE_LIST(doc, document, row *)
|
||||
CMC_GENERATE_LIST(doc, document, struct row *)
|
||||
|
||||
void row_deallocator(row *r)
|
||||
void row_deallocator(struct row *r)
|
||||
{
|
||||
row_free(r, NULL);
|
||||
}
|
||||
|
||||
document *document_load(const char *file_name);
|
||||
struct document *document_load(const char *file_name);
|
||||
void document_empty_line(FILE *fptr);
|
||||
void document_page_outline(FILE *fptr, int outline);
|
||||
void document_page_margin(FILE *fptr, int margin);
|
||||
void document_print(document *doc, FILE *fptr);
|
||||
void document_print(struct document *doc, FILE *fptr);
|
||||
|
||||
document *document_load(const char *file_name)
|
||||
struct document *document_load(const char *file_name)
|
||||
{
|
||||
FILE *file = fopen(file_name, "r");
|
||||
|
||||
@@ -31,9 +31,9 @@ document *document_load(const char *file_name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
row *initial_row = row_new(ROW_INI_CAP);
|
||||
struct row *initial_row = row_new(ROW_INI_CAP);
|
||||
|
||||
document *doc = doc_new(100);
|
||||
struct document *doc = doc_new(100);
|
||||
doc_push_back(doc, initial_row);
|
||||
|
||||
int ch;
|
||||
@@ -42,11 +42,11 @@ document *document_load(const char *file_name)
|
||||
{
|
||||
char c = (char)ch;
|
||||
|
||||
row *current_row = doc_back(doc);
|
||||
struct row *current_row = doc_back(doc);
|
||||
|
||||
if (c == '\n')
|
||||
{
|
||||
row *new_row = row_new(ROW_INI_CAP);
|
||||
struct row *new_row = row_new(ROW_INI_CAP);
|
||||
doc_push_back(doc, new_row);
|
||||
}
|
||||
else if (c == '\t')
|
||||
@@ -61,7 +61,7 @@ document *document_load(const char *file_name)
|
||||
|
||||
if (left > 0)
|
||||
{
|
||||
row *new_row = row_new(ROW_INI_CAP);
|
||||
struct row *new_row = row_new(ROW_INI_CAP);
|
||||
doc_push_back(doc, new_row);
|
||||
|
||||
while (left > 0)
|
||||
@@ -73,7 +73,7 @@ document *document_load(const char *file_name)
|
||||
}
|
||||
else if (DOC_LETTERS_IN_ROW == row_count(current_row))
|
||||
{
|
||||
row *new_row = row_new(ROW_INI_CAP);
|
||||
struct row *new_row = row_new(ROW_INI_CAP);
|
||||
row_push_back(new_row, c);
|
||||
doc_push_back(doc, new_row);
|
||||
}
|
||||
@@ -141,7 +141,7 @@ void document_page_margin(FILE *fptr, int margin /* 0 - first margin, 1 - second
|
||||
fputs("|\n", fptr);
|
||||
}
|
||||
|
||||
void document_print(document *doc, FILE *fptr)
|
||||
void document_print(struct document *doc, FILE *fptr)
|
||||
{
|
||||
fputc('\n', fptr);
|
||||
|
||||
@@ -153,7 +153,7 @@ void document_print(document *doc, FILE *fptr)
|
||||
if (current_page_row == 0)
|
||||
document_page_outline(fptr, 0);
|
||||
|
||||
row *current_row = doc_get(doc, i);
|
||||
struct row *current_row = doc_get(doc, i);
|
||||
|
||||
if (!current_row)
|
||||
cmc_log_fatal("Unexpected NULL pointer for %s", "current_row");
|
||||
@@ -198,7 +198,7 @@ int main(int argc, char const *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
document *doc = document_load(argv[1]);
|
||||
struct document *doc = document_load(argv[1]);
|
||||
|
||||
document_print(doc, stdout);
|
||||
|
||||
|
||||
Reference in new issue
Block a user