Skip to content

Commit

Permalink
simple write performance test
Browse files Browse the repository at this point in the history
  • Loading branch information
sjlombardo committed Jan 11, 2013
1 parent e238cc3 commit 1590037
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tests/Makefile.am
Expand Up @@ -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
Expand Down
69 changes: 69 additions & 0 deletions 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;
}

15 changes: 15 additions & 0 deletions 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"

0 comments on commit 1590037

Please sign in to comment.