From 1590037700ac8916b606233161d4232206603607 Mon Sep 17 00:00:00 2001 From: Stephen Lombardo Date: Fri, 11 Jan 2013 07:17:30 -0500 Subject: [PATCH] simple write performance test --- tests/Makefile.am | 4 ++- tests/c_perf.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++ tests/c_perf.test | 15 +++++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 tests/c_perf.c create mode 100755 tests/c_perf.test diff --git a/tests/Makefile.am b/tests/Makefile.am index 4ee27b6..7d95479 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -20,10 +20,12 @@ check_SCRIPTS = \ check_PROGRAMS = \ c_api \ c_thread_api \ - fsx + fsx \ + c_perf c_api_SOURCES = c_api.c c_thread_api_SOURCES = c_thread_api.c +c_perf_SOURCES = c_perf.c fsx_SOURCES = fsx.c if WITH_SQLCIPHER diff --git a/tests/c_perf.c b/tests/c_perf.c new file mode 100644 index 0000000..bb80587 --- /dev/null +++ b/tests/c_perf.c @@ -0,0 +1,69 @@ +#include "common.c" + +#define WRITESZ 2*1048576 +//#define WRITESZ 32768 +#define STARTSZ 256 +#define ENDSZ 32768 + +#define TIMING(t1,t2) \ + (double) (t2.tv_usec - t1.tv_usec)/1000000 + \ + (double) (t2.tv_sec - t1.tv_sec) + +void test_write_n_bytes_nosleep(sqlfs_t *sqlfs, int testsize) +{ + int i; + char testfilename[PATH_MAX]; + char randomdata[testsize]; + struct fuse_file_info fi = { 0 }; + randomfilename(testfilename, PATH_MAX, "write_n_bytes"); + sqlfs_proc_write(sqlfs, testfilename, randomdata, testsize, 0, &fi); +} + +int main(int argc, char *argv[]) +{ + char *database_filename = "c_perf.db"; + int rc, size, i; + sqlfs_t *sqlfs = 0; + struct timeval tstart, tstop; + + if(argc > 1) + database_filename = argv[1]; + if(exists(database_filename)) + printf("%s exists.\n", database_filename); + printf("Opening %s\n", database_filename); + sqlfs_init(database_filename); + printf("Running tests:\n"); + + rc = sqlfs_open(database_filename, &sqlfs); + printf("Opening database..."); + assert(rc); + printf("passed\n"); + + for (size=STARTSZ; size <= ENDSZ ; size *= 2) { + gettimeofday(&tstart, NULL); + for(i = 0; i < WRITESZ / size; i++) { + test_write_n_bytes_nosleep(sqlfs, size); + } + gettimeofday(&tstop, NULL); + printf("**** wrote %d bytes in %d %d byte chunks without transaction in %f seconds\n", + WRITESZ, WRITESZ / size, size, TIMING(tstart,tstop)); + } + + for (size=STARTSZ; size <= ENDSZ ; size *= 2) { + gettimeofday(&tstart, NULL); + sqlfs_begin_transaction(sqlfs); + for(i = 0; i < WRITESZ / size; i++) { + test_write_n_bytes_nosleep(sqlfs, size); + } + sqlfs_complete_transaction(sqlfs,1); + gettimeofday(&tstop, NULL); + printf("**** wrote %d bytes in %d %d byte chunks with transaction in %f seconds\n", + WRITESZ, WRITESZ / size, size, TIMING(tstart,tstop)); + } + + printf("Closing database..."); + sqlfs_close(sqlfs); + printf("done\n"); + return 0; +} + diff --git a/tests/c_perf.test b/tests/c_perf.test new file mode 100755 index 0000000..5ffb3ed --- /dev/null +++ b/tests/c_perf.test @@ -0,0 +1,15 @@ +## -*- sh -*- +## template for running a test C program + +# Common definitions +if test -z "$srcdir"; then + srcdir=`echo "$0" | sed 's,[^/]*$,,'` + test "$srcdir" = "$0" && srcdir=. + test -z "$srcdir" && srcdir=. + test "${V+set}" != set && V=1 +fi +. $srcdir/defs + +test="$testdir/$testname" +echo "Running $test" +"$test" "$testsubdir/$testname.db"