nostrdb

an unfairly fast embedded nostr database backed by lmdb
git clone git://jb55.com/nostrdb
Log | Files | Refs | Submodules | README | LICENSE

bench-ingest.c (1197B)


      1 
      2 
      3 #include "io.h"
      4 #include "nostrdb.h"
      5 #include <sys/mman.h>
      6 #include <time.h>
      7 #include <stdlib.h>
      8 #include <assert.h>
      9 
     10 static int bench_parser(int times)
     11 {
     12 	char *json = malloc(1024 * 100);
     13 	int i, mapsize, written, ingester_threads;
     14 	long nanos, ms;
     15 	static const int alloc_size = 2 << 18;
     16 	struct ndb *ndb;
     17 	struct timespec t1, t2;
     18 
     19 	written = 0;
     20 	mapsize = 1024 * 1024 * 100;
     21 	ingester_threads = 8;
     22 	assert(ndb_init(&ndb, "testdata/db", mapsize, ingester_threads, 0));
     23 	read_file("testdata/contacts-event.json", (unsigned char*)json, alloc_size, &written);
     24 
     25 	clock_gettime(CLOCK_MONOTONIC, &t1);
     26 
     27 	for (i = 0; i < times; i++) {
     28 		ndb_process_event(ndb, json, written);
     29 	}
     30 
     31 	free(json);
     32 	ndb_destroy(ndb);
     33 
     34 	clock_gettime(CLOCK_MONOTONIC, &t2);
     35 
     36 	nanos = (t2.tv_sec - t1.tv_sec) * (long)1e9 + (t2.tv_nsec - t1.tv_nsec);
     37 	ms = nanos / 1e6;
     38 	printf("ns/run\t%ld\nms/run\t%f\nns\t%ld\nms\t%ld\n",
     39 		nanos/times, (double)ms/(double)times, nanos, ms);
     40 
     41 	return 1;
     42 }
     43 
     44 int main(int argc, char *argv[], char **env)
     45 {
     46 	int times = 50000;
     47 
     48 	if (argc >= 2)
     49 		times = atoi(argv[1]);
     50 
     51 	fprintf(stderr, "benching %d duplicate contact events\n", times);
     52 	if (!bench_parser(times))
     53 		return 2;
     54 	
     55 	return 0;
     56 }
     57