X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=testing%2Fdata_performance%2Fsqlite.c;fp=testing%2Fdata_performance%2Fsqlite.c;h=b0ffb367cd731a3495787b26353b85bc22c11de8;hb=cdc9404739cec84843bc96031e957041d19608a6;hp=0000000000000000000000000000000000000000;hpb=cb4eb97e6d35fcb1e1493682afb2fe4a4bda29b6;p=matches%2FMCTX3420.git diff --git a/testing/data_performance/sqlite.c b/testing/data_performance/sqlite.c new file mode 100644 index 0000000..b0ffb36 --- /dev/null +++ b/testing/data_performance/sqlite.c @@ -0,0 +1,65 @@ +#include +#include +#include +#include +#include + +typedef struct +{ + float time; + float value; +} DataPoint; + + + + +int main(int argc, char ** argv) +{ + assert(argc == 3); + + int bufsiz = atoi(argv[1]); + int numpoints = atoi(argv[2]); + assert(bufsiz > 0); + DataPoint * buffer = (DataPoint*)(calloc(bufsiz, sizeof(DataPoint))); + + + + sqlite3 * db; + sqlite3_open("sqlite.db", &db); + + + char query[BUFSIZ]; + char * query_value = query+sprintf(query,"insert into sensor values("); + + + struct timeval start_time; + gettimeofday(&start_time, NULL); + + int i = 0; + while (i < numpoints) + { + int j = 0; + for (j = 0; j < bufsiz && i < numpoints; ++j) + { + buffer[j].time = i; + buffer[j].value = i; + + } + i += j; + for (int k = 0; k < j; ++k) + { + sprintf(query_value,"%f,%f)", buffer[k].time, buffer[k].value); + sqlite3_exec(db, query, NULL, NULL, NULL); + } + } + + struct timeval end_time; + gettimeofday(&end_time, NULL); + + + sqlite3_close(db); + free(buffer); + float time_elapsed = (float)(end_time.tv_sec - start_time.tv_sec) + 1e-6*(end_time.tv_usec - start_time.tv_usec); + printf("%f\n", time_elapsed); + return 0; +}