mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
indent
This commit is contained in:
parent
cf02d065cf
commit
f583c90dc3
1 changed files with 192 additions and 170 deletions
362
test/test_list.c
362
test/test_list.c
|
@ -9,200 +9,222 @@
|
||||||
|
|
||||||
#define NELEMS 100
|
#define NELEMS 100
|
||||||
|
|
||||||
int main (int argc, char **argv) {
|
int
|
||||||
uint8_t verbose = argc > 1;
|
main (int argc, char **argv)
|
||||||
int i, k, n, ret;
|
{
|
||||||
|
uint8_t verbose = argc > 1;
|
||||||
|
int i, k, n, ret;
|
||||||
|
|
||||||
PsycParseListState listState;
|
PsycParseListState listState;
|
||||||
PsycList list_text, list_bin;
|
PsycList list_text, list_bin;
|
||||||
PsycString elems_text[NELEMS], elems_bin[NELEMS], elem;
|
PsycString elems_text[NELEMS], elems_bin[NELEMS], elem;
|
||||||
char buf_text[NELEMS * 200], buf_bin[NELEMS * 200], *elems[NELEMS], **elems2 = NULL;
|
char buf_text[NELEMS * 200], buf_bin[NELEMS * 200], *elems[NELEMS], **elems2 = NULL;
|
||||||
|
|
||||||
struct timeval start, end;
|
struct timeval start, end;
|
||||||
|
|
||||||
for (i=0; i<NELEMS; i++)
|
for (i=0; i<NELEMS; i++)
|
||||||
elems_text[i] = (PsycString) PSYC_C2STR("1234567890abcdefghijklmnopqrstuvwxyz-._ 1234567890abcdefghijklmnopqrstuvwxyz-._ 1234567890abcdefghijklmnopqrstuvwxyz-._ 1234567890");
|
elems_text[i] = PSYC_C2STR("1234567890abcdefghijklmnopqrstuvwxyz-._ "
|
||||||
|
"1234567890abcdefghijklmnopqrstuvwxyz-._ "
|
||||||
|
"1234567890abcdefghijklmnopqrstuvwxyz-._ "
|
||||||
|
"1234567890");
|
||||||
|
for (i=0; i<NELEMS; i++)
|
||||||
|
elems_bin[i] = PSYC_C2STR("1234567890|abcdefghijklmnopqrstuvwxyz|_\n"
|
||||||
|
"1234567890|abcdefghijklmnopqrstuvwxyz|_\n"
|
||||||
|
"1234567890|abcdefghijklmnopqrstuvwxyz|_\n"
|
||||||
|
"1234567890");
|
||||||
|
|
||||||
for (i=0; i<NELEMS; i++)
|
psyc_list_init(&list_text, elems_text, PSYC_NUM_ELEM(elems_text),
|
||||||
elems_bin[i] = (PsycString) PSYC_C2STR("1234567890|abcdefghijklmnopqrstuvwxyz|_\n1234567890|abcdefghijklmnopqrstuvwxyz|_\n1234567890|abcdefghijklmnopqrstuvwxyz|_\n1234567890");
|
PSYC_LIST_NO_LENGTH);
|
||||||
|
psyc_list_init(&list_bin, elems_bin, PSYC_NUM_ELEM(elems_bin),
|
||||||
|
PSYC_LIST_CHECK_LENGTH);
|
||||||
|
|
||||||
psyc_list_init(&list_text, elems_text, PSYC_NUM_ELEM(elems_text), PSYC_LIST_NO_LENGTH);
|
psyc_render_list(&list_text, buf_text, sizeof(buf_text));
|
||||||
psyc_list_init(&list_bin, elems_bin, PSYC_NUM_ELEM(elems_bin), PSYC_LIST_CHECK_LENGTH);
|
psyc_render_list(&list_bin, buf_bin, sizeof(buf_bin));
|
||||||
|
|
||||||
psyc_render_list(&list_text, buf_text, sizeof(buf_text));
|
printf("list_text: %ld\n%.*s\n",
|
||||||
psyc_render_list(&list_bin, buf_bin, sizeof(buf_bin));
|
list_text.length, (int)list_text.length, buf_text);
|
||||||
|
printf("list_bin: %ld\n%.*s\n",
|
||||||
printf("list_text: %ld\n%.*s\n", list_text.length, (int)list_text.length, buf_text);
|
list_bin.length, (int)list_bin.length, buf_bin);
|
||||||
printf("list_bin: %ld\n%.*s\n", list_bin.length, (int)list_bin.length, buf_bin);
|
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
printf("parsing text list to elems[]\n");
|
printf("parsing text list to elems[]\n");
|
||||||
gettimeofday(&start, NULL);
|
gettimeofday(&start, NULL);
|
||||||
for (n = 0; n < NELEMS; n++) {
|
for (n = 0; n < NELEMS; n++) {
|
||||||
psyc_parse_list_state_init(&listState);
|
psyc_parse_list_state_init(&listState);
|
||||||
psyc_parse_list_buffer_set(&listState, buf_text, list_text.length);
|
psyc_parse_list_buffer_set(&listState, buf_text, list_text.length);
|
||||||
i = 0;
|
i = 0;
|
||||||
do {
|
do {
|
||||||
ret = psyc_parse_list(&listState, &elem);
|
ret = psyc_parse_list(&listState, &elem);
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case PSYC_PARSE_LIST_END:
|
case PSYC_PARSE_LIST_END:
|
||||||
ret = 0;
|
ret = 0;
|
||||||
case PSYC_PARSE_LIST_ELEM:
|
case PSYC_PARSE_LIST_ELEM:
|
||||||
if (verbose) printf("|%d: %.*s... (%ld)\n", i, 10, elem.data, elem.length);
|
if (verbose)
|
||||||
//elems[i] = malloc(elem.length);
|
printf("|%d: %.*s... (%ld)\n", i, 10, elem.data, elem.length);
|
||||||
//memcpy(&elems[i++], elem.data, elem.length);
|
//elems[i] = malloc(elem.length);
|
||||||
break;
|
//memcpy(&elems[i++], elem.data, elem.length);
|
||||||
default:
|
break;
|
||||||
printf("# Error while parsing list: %i\n", ret);
|
default:
|
||||||
ret = -1;
|
printf("# Error while parsing list: %i\n", ret);
|
||||||
}
|
ret = -1;
|
||||||
} while (ret > 0);
|
}
|
||||||
}
|
} while (ret > 0);
|
||||||
gettimeofday(&end, NULL);
|
}
|
||||||
//printf("%ld ms\n", (end.tv_sec * 1000000 + end.tv_usec - start.tv_sec * 1000000 - start.tv_usec) / 1000);
|
gettimeofday(&end, NULL);
|
||||||
printf("%ld us\n", (end.tv_sec * 1000000 + end.tv_usec - start.tv_sec * 1000000 - start.tv_usec));
|
// printf("%ld ms\n", (end.tv_sec * 1000000 + end.tv_usec
|
||||||
|
// - start.tv_sec * 1000000 - start.tv_usec) / 1000);
|
||||||
|
printf("%ld us\n", (end.tv_sec * 1000000 + end.tv_usec
|
||||||
|
- start.tv_sec * 1000000 - start.tv_usec));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
printf("parsing binary list to elems[]\n");
|
printf("parsing binary list to elems[]\n");
|
||||||
gettimeofday(&start, NULL);
|
gettimeofday(&start, NULL);
|
||||||
for (n = 0; n < NELEMS; n++) {
|
for (n = 0; n < NELEMS; n++) {
|
||||||
psyc_parse_list_state_init(&listState);
|
psyc_parse_list_state_init(&listState);
|
||||||
psyc_parse_list_buffer_set(&listState, buf_bin, list_bin.length);
|
psyc_parse_list_buffer_set(&listState, buf_bin, list_bin.length);
|
||||||
i = 0;
|
i = 0;
|
||||||
do {
|
do {
|
||||||
ret = psyc_parse_list(&listState, &elem);
|
ret = psyc_parse_list(&listState, &elem);
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case PSYC_PARSE_LIST_END:
|
case PSYC_PARSE_LIST_END:
|
||||||
ret = 0;
|
ret = 0;
|
||||||
case PSYC_PARSE_LIST_ELEM:
|
case PSYC_PARSE_LIST_ELEM:
|
||||||
//if (verbose) printf("|%.*s\n", (int)elem.length, elem.data);
|
//if (verbose) printf("|%.*s\n", (int)elem.length, elem.data);
|
||||||
if (verbose) printf("|%d: %.*s... (%ld)\n", i, 10, elem.data, elem.length);
|
if (verbose) printf("|%d: %.*s... (%ld)\n", i, 10, elem.data, elem.length);
|
||||||
elems[i] = malloc(elem.length);
|
elems[i] = malloc(elem.length);
|
||||||
memcpy(elems[i++], elem.data, elem.length);
|
memcpy(elems[i++], elem.data, elem.length);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("# Error while parsing list: %i\n", ret);
|
printf("# Error while parsing list: %i\n", ret);
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
} while (ret > 0);
|
} while (ret > 0);
|
||||||
}
|
}
|
||||||
gettimeofday(&end, NULL);
|
gettimeofday(&end, NULL);
|
||||||
//printf("%ld ms\n", (end.tv_sec * 1000000 + end.tv_usec - start.tv_sec * 1000000 - start.tv_usec));
|
// printf("%ld ms\n", (end.tv_sec * 1000000 + end.tv_usec
|
||||||
printf("%ld us\n", (end.tv_sec * 1000000 + end.tv_usec - start.tv_sec * 1000000 - start.tv_usec));
|
// - start.tv_sec * 1000000 - start.tv_usec));
|
||||||
|
printf("%ld us\n", (end.tv_sec * 1000000 + end.tv_usec
|
||||||
|
- start.tv_sec * 1000000 - start.tv_usec));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
printf("parsing binary list to elems2[] with realloc\n");
|
printf("parsing binary list to elems2[] with realloc\n");
|
||||||
gettimeofday(&start, NULL);
|
gettimeofday(&start, NULL);
|
||||||
for (n = 0; n < NELEMS; n++) {
|
for (n = 0; n < NELEMS; n++) {
|
||||||
psyc_parse_list_state_init(&listState);
|
psyc_parse_list_state_init(&listState);
|
||||||
psyc_parse_list_buffer_set(&listState, buf_bin, list_bin.length);
|
psyc_parse_list_buffer_set(&listState, buf_bin, list_bin.length);
|
||||||
i = 0;
|
i = 0;
|
||||||
do {
|
do {
|
||||||
ret = psyc_parse_list(&listState, &elem);
|
ret = psyc_parse_list(&listState, &elem);
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case PSYC_PARSE_LIST_END:
|
case PSYC_PARSE_LIST_END:
|
||||||
ret = 0;
|
ret = 0;
|
||||||
case PSYC_PARSE_LIST_ELEM:
|
case PSYC_PARSE_LIST_ELEM:
|
||||||
if (elems2)
|
if (elems2)
|
||||||
elems2 = realloc(elems2, (i+1) * sizeof(char*));
|
elems2 = realloc(elems2, (i+1) * sizeof(char*));
|
||||||
else
|
else
|
||||||
elems2 = malloc((i+1) * sizeof(char*));
|
elems2 = malloc((i+1) * sizeof(char*));
|
||||||
|
|
||||||
elems2[i] = malloc(elem.length);
|
elems2[i] = malloc(elem.length);
|
||||||
memcpy(elems2[i++], elem.data, elem.length);
|
memcpy(elems2[i++], elem.data, elem.length);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("# Error while parsing list: %i\n", ret);
|
printf("# Error while parsing list: %i\n", ret);
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
} while (ret > 0);
|
} while (ret > 0);
|
||||||
}
|
}
|
||||||
gettimeofday(&end, NULL);
|
gettimeofday(&end, NULL);
|
||||||
//printf("%ld ms\n", (end.tv_sec * 1000000 + end.tv_usec - start.tv_sec * 1000000 - start.tv_usec));
|
// printf("%ld ms\n", (end.tv_sec * 1000000 + end.tv_usec
|
||||||
printf("%ld us\n", (end.tv_sec * 1000000 + end.tv_usec - start.tv_sec * 1000000 - start.tv_usec));
|
// - start.tv_sec * 1000000 - start.tv_usec));
|
||||||
|
printf("%ld us\n", (end.tv_sec * 1000000 + end.tv_usec
|
||||||
|
- start.tv_sec * 1000000 - start.tv_usec));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
printf("parsing binary list to elems2[] with malloc\n");
|
printf("parsing binary list to elems2[] with malloc\n");
|
||||||
gettimeofday(&start, NULL);
|
gettimeofday(&start, NULL);
|
||||||
for (n = 0; n < NELEMS; n++) {
|
for (n = 0; n < NELEMS; n++) {
|
||||||
psyc_parse_list_state_init(&listState);
|
psyc_parse_list_state_init(&listState);
|
||||||
psyc_parse_list_buffer_set(&listState, buf_bin, list_bin.length);
|
psyc_parse_list_buffer_set(&listState, buf_bin, list_bin.length);
|
||||||
i = 0;
|
i = 0;
|
||||||
do {
|
do {
|
||||||
ret = psyc_parse_list(&listState, &elem);
|
ret = psyc_parse_list(&listState, &elem);
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case PSYC_PARSE_LIST_END:
|
case PSYC_PARSE_LIST_END:
|
||||||
ret = 0;
|
ret = 0;
|
||||||
case PSYC_PARSE_LIST_ELEM:
|
case PSYC_PARSE_LIST_ELEM:
|
||||||
/*
|
/*
|
||||||
if (elems2)
|
if (elems2)
|
||||||
elems2 = realloc(elems2, (i+1) * sizeof(char*));
|
elems2 = realloc(elems2, (i+1) * sizeof(char*));
|
||||||
else
|
else
|
||||||
elems2 = malloc((i+1) * sizeof(char*));
|
elems2 = malloc((i+1) * sizeof(char*));
|
||||||
*/
|
*/
|
||||||
elems2 = malloc(sizeof(char*));
|
elems2 = malloc(sizeof(char*));
|
||||||
elems2[i] = malloc(elem.length);
|
elems2[i] = malloc(elem.length);
|
||||||
memcpy(elems2[i], elem.data, elem.length);
|
memcpy(elems2[i], elem.data, elem.length);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("# Error while parsing list: %i\n", ret);
|
printf("# Error while parsing list: %i\n", ret);
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
} while (ret > 0);
|
} while (ret > 0);
|
||||||
}
|
}
|
||||||
gettimeofday(&end, NULL);
|
gettimeofday(&end, NULL);
|
||||||
//printf("%ld ms\n", (end.tv_sec * 1000000 + end.tv_usec - start.tv_sec * 1000000 - start.tv_usec));
|
// printf("%ld ms\n", (end.tv_sec * 1000000 + end.tv_usec
|
||||||
printf("%ld us\n", (end.tv_sec * 1000000 + end.tv_usec - start.tv_sec * 1000000 - start.tv_usec));
|
// - start.tv_sec * 1000000 - start.tv_usec));
|
||||||
|
printf("%ld us\n", (end.tv_sec * 1000000 + end.tv_usec
|
||||||
|
- start.tv_sec * 1000000 - start.tv_usec));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
printf("parsing binary list to elems2[] with double-parsing\n");
|
printf("parsing binary list to elems2[] with double-parsing\n");
|
||||||
gettimeofday(&start, NULL);
|
gettimeofday(&start, NULL);
|
||||||
for (n = 0; n < NELEMS; n++) {
|
for (n = 0; n < NELEMS; n++) {
|
||||||
psyc_parse_list_state_init(&listState);
|
psyc_parse_list_state_init(&listState);
|
||||||
psyc_parse_list_buffer_set(&listState, buf_bin, list_bin.length);
|
psyc_parse_list_buffer_set(&listState, buf_bin, list_bin.length);
|
||||||
i = 0;
|
i = 0;
|
||||||
k = 0;
|
k = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
ret = psyc_parse_list(&listState, &elem);
|
ret = psyc_parse_list(&listState, &elem);
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case PSYC_PARSE_LIST_END:
|
case PSYC_PARSE_LIST_END:
|
||||||
ret = 0;
|
ret = 0;
|
||||||
case PSYC_PARSE_LIST_ELEM:
|
case PSYC_PARSE_LIST_ELEM:
|
||||||
k++;
|
k++;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("# Error while parsing list: %i\n", ret);
|
printf("# Error while parsing list: %i\n", ret);
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
} while (ret > 0);
|
} while (ret > 0);
|
||||||
|
|
||||||
elems2 = malloc(k * sizeof(char*));
|
elems2 = malloc(k * sizeof(char*));
|
||||||
psyc_parse_list_buffer_set(&listState, buf_bin, list_bin.length);
|
psyc_parse_list_buffer_set(&listState, buf_bin, list_bin.length);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
ret = psyc_parse_list(&listState, &elem);
|
ret = psyc_parse_list(&listState, &elem);
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case PSYC_PARSE_LIST_END:
|
case PSYC_PARSE_LIST_END:
|
||||||
ret = 0;
|
ret = 0;
|
||||||
case PSYC_PARSE_LIST_ELEM:
|
case PSYC_PARSE_LIST_ELEM:
|
||||||
elems2[i] = malloc(elem.length);
|
elems2[i] = malloc(elem.length);
|
||||||
memcpy(elems2[i++], elem.data, elem.length);
|
memcpy(elems2[i++], elem.data, elem.length);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("# Error while parsing list: %i\n", ret);
|
printf("# Error while parsing list: %i\n", ret);
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
} while (ret > 0);
|
} while (ret > 0);
|
||||||
}
|
}
|
||||||
gettimeofday(&end, NULL);
|
gettimeofday(&end, NULL);
|
||||||
//printf("%ld ms\n", (end.tv_sec * 1000000 + end.tv_usec - start.tv_sec * 1000000 - start.tv_usec));
|
// printf("%ld ms\n", (end.tv_sec * 1000000 + end.tv_usec
|
||||||
printf("%ld us\n", (end.tv_sec * 1000000 + end.tv_usec - start.tv_sec * 1000000 - start.tv_usec));
|
// - start.tv_sec * 1000000 - start.tv_usec));
|
||||||
|
printf("%ld us\n", (end.tv_sec * 1000000 + end.tv_usec
|
||||||
|
- start.tv_sec * 1000000 - start.tv_usec));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue