diff options
Diffstat (limited to 'contrib/csv-perf.c')
| -rw-r--r-- | contrib/csv-perf.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/contrib/csv-perf.c b/contrib/csv-perf.c new file mode 100644 index 0000000..1c0f7a3 --- /dev/null +++ b/contrib/csv-perf.c | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | #include <assert.h> | ||
| 2 | #include <stdio.h> | ||
| 3 | #include <stdlib.h> | ||
| 4 | #include <time.h> | ||
| 5 | |||
| 6 | #include "csv.h" | ||
| 7 | |||
| 8 | static int | ||
| 9 | test(FILE *f) | ||
| 10 | { | ||
| 11 | int line = 0; | ||
| 12 | csv_t csv = { 0 }; | ||
| 13 | |||
| 14 | while ( csv_read(&csv, f) ) { | ||
| 15 | ++line; | ||
| 16 | } | ||
| 17 | |||
| 18 | return line; | ||
| 19 | } | ||
| 20 | |||
| 21 | int | ||
| 22 | main(int argc, char *argv[]) | ||
| 23 | { | ||
| 24 | if ( argc != 2 ) { | ||
| 25 | fprintf(stderr, "usage: %s testfile\n", argv[0]); | ||
| 26 | return EXIT_FAILURE; | ||
| 27 | } | ||
| 28 | |||
| 29 | FILE *in = fopen(argv[1], "r"); | ||
| 30 | if ( in == NULL ) { | ||
| 31 | fprintf(stderr, "failed to open testfile...\n"); | ||
| 32 | return EXIT_FAILURE; | ||
| 33 | } | ||
| 34 | |||
| 35 | clock_t start = clock(); | ||
| 36 | |||
| 37 | int lines = test(in); | ||
| 38 | |||
| 39 | clock_t end = clock(); | ||
| 40 | |||
| 41 | fclose(in); | ||
| 42 | |||
| 43 | printf("%d lines processed, duration: %.3lf sec\n", lines, ((double) (end - start)) / CLOCKS_PER_SEC); | ||
| 44 | |||
| 45 | return EXIT_SUCCESS; | ||
| 46 | } | ||
