Created
July 10, 2015 05:08
-
-
Save isagalaev/523a93f837976c9b3682 to your computer and use it in GitHub Desktop.
yajl performance test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <time.h> | |
#include <yajl/yajl_parse.h> | |
unsigned char buffer[64 * 1024]; | |
unsigned int count = 0; | |
int count_string(void *ctx, const unsigned char *value, size_t length) { | |
if (!count) { | |
printf("%.*s\n", (int)length, value); | |
} | |
count += 1; | |
return 1; | |
} | |
yajl_callbacks callbacks = { | |
NULL, | |
NULL, | |
NULL, | |
NULL, | |
NULL, | |
count_string, | |
NULL, | |
NULL, | |
NULL, | |
NULL, | |
NULL | |
}; | |
int main() { | |
yajl_handle handle; | |
size_t len; | |
yajl_status status = yajl_status_ok; | |
clock_t start, end; | |
start = clock(); | |
handle = yajl_alloc(&callbacks, NULL, NULL); | |
for (;;) { | |
len = fread(buffer, 1, sizeof(buffer), stdin); | |
if (!len) | |
break; | |
status = yajl_parse(handle, buffer, len); | |
if (status != yajl_status_ok) | |
break; | |
} | |
status = yajl_complete_parse(handle); | |
yajl_free(handle); | |
end = clock(); | |
if (status == yajl_status_ok) { | |
printf("%f\n", (double)(end - start) / CLOCKS_PER_SEC); | |
printf("Strings: %d\n", count); | |
} else { | |
printf("Error\n"); | |
} | |
return status; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment