git » nmdb » commit ad6fe07

Add three new tests: set.c, get.c and del.c.

author Alberto Bertogli
2007-06-20 07:01:38 UTC
committer Alberto Bertogli
2007-06-20 07:01:38 UTC
parent 278d064ed113cd3f9e93c29e4c7f3eebdb5effcc

Add three new tests: set.c, get.c and del.c.

They're like 2.c but perform only a single operation. Useful not only for
single operation benchmarks, but to populate the server.

The build.sh changes also fix the script, which wasn't handling compiler
flags correctly.

Signed-off-by: Alberto Bertogli <albertito@gmail.com>

tests/c/build.sh +14 -15
tests/c/del.c +70 -0
tests/c/get.c +77 -0
tests/c/set.c +76 -0

diff --git a/tests/c/build.sh b/tests/c/build.sh
index cec62b8..a38525c 100755
--- a/tests/c/build.sh
+++ b/tests/c/build.sh
@@ -7,21 +7,20 @@ Use: build.sh [build|debug_build|strict_build|profile_build|clean]
 "
 
 
-CF="-std=c99 -Wall -O3"
-ALLCF="-D_XOPEN_SOURCE=500 -fPIC $CF"
+ALLCF="-D_XOPEN_SOURCE=500 -fPIC -std=c99 -Wall -O3"
 
 case "$1" in
 	"build" )
 		# defaults are just fine for build
 		;;
 	"debug_build" )
-		ALLCF="-g $CF"
+		ALLCF="$ALLCF -g"
 		;;
 	"strict_build" )
-		ALLCF="-ansi -pedantic $CF"
+		ALLCF="$ALLCF -ansi -pedantic"
 		;;
 	"profile_build" )
-		ALLCF="-g -pg -fprofile-arcs -ftest-coverage $CF"
+		ALLCF="$ALLCF -g -pg -fprofile-arcs -ftest-coverage"
 		;;
 	"clean" )
 		CLEAN=1
@@ -36,16 +35,16 @@ esac;
 for p in TIPC TCP UDP MULT; do
 	for v in NORMAL CACHE SYNC; do
 		OP=`echo $p-$v | tr '[A-Z]' '[a-z]'`
-		CF="-DUSE_$p=1 -DUSE_$v=1"
-
-		if [ "$CLEAN" == 1 ]; then
-			rm -vf 1-$OP 2-$OP 3-$OP
-		else
-			echo " * $OP"
-			cc -lnmdb $CF -o 1-$OP 1.c
-			cc -lnmdb $CF -o 2-$OP 2.c
-			cc -lnmdb $CF -o 3-$OP 3.c
-		fi
+		TF="-DUSE_$p=1 -DUSE_$v=1"
+
+		echo " * $OP"
+		for t in 1 2 3 "set" "get" "del"; do
+			if [ "$CLEAN" == 1 ]; then
+				rm -vf $t-$OP
+			else
+				cc -lnmdb $ALLCF $TF -o $t-$OP $t.c
+			fi
+		done
 	done
 done
 
diff --git a/tests/c/del.c b/tests/c/del.c
new file mode 100644
index 0000000..2948fb4
--- /dev/null
+++ b/tests/c/del.c
@@ -0,0 +1,70 @@
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <stdlib.h>
+
+#include <nmdb.h>
+#include "timer.h"
+#include "prototypes.h"
+
+
+int main(int argc, char **argv)
+{
+	int i, r, times;
+	unsigned char *key;
+	size_t ksize;
+	unsigned long d_elapsed;
+	nmdb_t *db;
+
+	if (argc != 3) {
+		printf("Usage: test2 TIMES KSIZE\n");
+		return 1;
+	}
+
+	times = atoi(argv[1]);
+	ksize = atoi(argv[2]);
+	if (times < 1) {
+		printf("Error: TIMES must be >= 1\n");
+		return 1;
+	}
+	if (ksize < sizeof(int)) {
+		printf("Error: KSIZE must be >= sizeof(int)\n");
+		return 1;
+	}
+
+	key = malloc(ksize);
+	memset(key, 0, ksize);
+
+	if (key == NULL) {
+		perror("Error: malloc()");
+		return 1;
+	}
+
+	db = nmdb_init();
+	if (db == NULL) {
+		perror("nmdb_init() failed");
+		return 1;
+	}
+
+	NADDSRV(db);
+
+	timer_start();
+	for (i = 0; i < times; i++) {
+		* (int *) key = i;
+		r = NDEL(db, key, ksize);
+		if (r < 0) {
+			perror("Del");
+			return 1;
+		}
+	}
+	d_elapsed = timer_stop();
+	printf("%lu\n", d_elapsed);
+
+	free(key);
+	nmdb_free(db);
+
+	return 0;
+}
+
diff --git a/tests/c/get.c b/tests/c/get.c
new file mode 100644
index 0000000..01a980f
--- /dev/null
+++ b/tests/c/get.c
@@ -0,0 +1,77 @@
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <stdlib.h>
+
+#include <nmdb.h>
+#include "timer.h"
+#include "prototypes.h"
+
+
+int main(int argc, char **argv)
+{
+	int i, r, times;
+	unsigned char *key, *val;
+	size_t ksize, vsize;
+	unsigned long g_elapsed, misses = 0;
+	nmdb_t *db;
+
+	if (argc != 4) {
+		printf("Usage: get-* TIMES KSIZE\n");
+		return 1;
+	}
+
+	times = atoi(argv[1]);
+	ksize = atoi(argv[2]);
+	if (times < 1) {
+		printf("Error: TIMES must be >= 1\n");
+		return 1;
+	}
+	if (ksize < sizeof(int)) {
+		printf("Error: KSIZE must be >= sizeof(int)\n");
+		return 1;
+	}
+
+	key = malloc(ksize);
+	memset(key, 0, ksize);
+	vsize = 70 * 1024;
+	val = malloc(vsize);
+	memset(val, 0, vsize);
+
+	if (key == NULL || val == NULL) {
+		perror("Error: malloc()");
+		return 1;
+	}
+
+	db = nmdb_init();
+	if (db == NULL) {
+		perror("nmdb_init() failed");
+		return 1;
+	}
+
+	NADDSRV(db);
+
+	timer_start();
+	for (i = 0; i < times; i++) {
+		* (int *) key = i;
+		r = NGET(db, key, ksize, val, vsize);
+		if (r < 0) {
+			perror("Get");
+			return 1;
+		} else if (r == 0) {
+			misses++;
+		}
+	}
+	g_elapsed = timer_stop();
+
+	printf("%lu m:%lu\n", g_elapsed, misses);
+
+	free(key);
+	free(val);
+	nmdb_free(db);
+
+	return 0;
+}
+
diff --git a/tests/c/set.c b/tests/c/set.c
new file mode 100644
index 0000000..7e556c8
--- /dev/null
+++ b/tests/c/set.c
@@ -0,0 +1,76 @@
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <stdlib.h>
+
+#include <nmdb.h>
+#include "timer.h"
+#include "prototypes.h"
+
+
+int main(int argc, char **argv)
+{
+	int i, r, times;
+	unsigned char *key, *val;
+	size_t ksize, vsize;
+	unsigned long s_elapsed;
+	nmdb_t *db;
+
+	if (argc != 4) {
+		printf("Usage: set-* TIMES KSIZE VSIZE\n");
+		return 1;
+	}
+
+	times = atoi(argv[1]);
+	ksize = atoi(argv[2]);
+	vsize = atoi(argv[3]);
+	if (times < 1) {
+		printf("Error: TIMES must be >= 1\n");
+		return 1;
+	}
+	if (ksize < sizeof(int) || vsize < sizeof(int)) {
+		printf("Error: KSIZE and VSIZE must be >= sizeof(int)\n");
+		return 1;
+	}
+
+	key = malloc(ksize);
+	memset(key, 0, ksize);
+	val = malloc(vsize);
+	memset(val, 0, vsize);
+
+	if (key == NULL || val == NULL) {
+		perror("Error: malloc()");
+		return 1;
+	}
+
+	db = nmdb_init();
+	if (db == NULL) {
+		perror("nmdb_init() failed");
+		return 1;
+	}
+
+	NADDSRV(db);
+
+	timer_start();
+	for (i = 0; i < times; i++) {
+		* (int *) key = i;
+		* (int *) val = i;
+		r = NSET(db, key, ksize, val, vsize);
+		if (r < 0) {
+			perror("Set");
+			return 1;
+		}
+	}
+	s_elapsed = timer_stop();
+
+	printf("%lu\n", s_elapsed);
+
+	free(key);
+	free(val);
+	nmdb_free(db);
+
+	return 0;
+}
+