From 7d956c533e9fd7d3bbb9a4a8b7f89f0fe54d4bc3 Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Sun, 13 Apr 2025 22:43:46 +0200 Subject: first draft --- contrib/csv-perf.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 contrib/csv-perf.c (limited to 'contrib/csv-perf.c') 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 @@ +#include +#include +#include +#include + +#include "csv.h" + +static int +test(FILE *f) +{ + int line = 0; + csv_t csv = { 0 }; + + while ( csv_read(&csv, f) ) { + ++line; + } + + return line; +} + +int +main(int argc, char *argv[]) +{ + if ( argc != 2 ) { + fprintf(stderr, "usage: %s testfile\n", argv[0]); + return EXIT_FAILURE; + } + + FILE *in = fopen(argv[1], "r"); + if ( in == NULL ) { + fprintf(stderr, "failed to open testfile...\n"); + return EXIT_FAILURE; + } + + clock_t start = clock(); + + int lines = test(in); + + clock_t end = clock(); + + fclose(in); + + printf("%d lines processed, duration: %.3lf sec\n", lines, ((double) (end - start)) / CLOCKS_PER_SEC); + + return EXIT_SUCCESS; +} -- cgit v1.3