From b4065012631b59999a5381bbe1cd42d53665b0eb Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Mon, 12 Dec 2022 03:11:32 +0000 Subject: [PATCH] Start of a benchmark. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4076 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- src/ssb.db.c | 1 - src/ssb.tests.c | 35 +++++++++++++++++++++++++++++++++++ src/ssb.tests.h | 1 + src/tests.c | 1 + 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/ssb.db.c b/src/ssb.db.c index 5cb07c95..aac14f20 100644 --- a/src/ssb.db.c +++ b/src/ssb.db.c @@ -279,7 +279,6 @@ bool tf_ssb_db_store_message(tf_ssb_t* ssb, JSContext* context, const char* id, { printf("%s\n", sqlite3_errmsg(db)); } - printf("changes = %d\n", sqlite3_changes(db)); stored = r == SQLITE_DONE && sqlite3_changes(db) != 0; if (stored) { diff --git a/src/ssb.tests.c b/src/ssb.tests.c index 963b38c3..fc6c5839 100644 --- a/src/ssb.tests.c +++ b/src/ssb.tests.c @@ -542,3 +542,38 @@ void tf_ssb_test_following(const tf_test_options_t* options) sqlite3_close(db0); } + +void tf_ssb_test_bench(const tf_test_options_t* options) +{ + printf("Testing following.\n"); + sqlite3* db0 = NULL; + int r = sqlite3_open(":memory:", &db0); + (void)r; + assert(r == SQLITE_OK); + + uv_loop_t loop = { 0 }; + uv_loop_init(&loop); + + tf_ssb_t* ssb0 = tf_ssb_create(&loop, NULL, db0); + tf_ssb_generate_keys(ssb0); + + char id0[k_id_base64_len] = { 0 }; + tf_ssb_whoami(ssb0, id0, sizeof(id0)); + + struct timespec start_time = { 0 }; + struct timespec end_time = { 0 }; + clock_gettime(CLOCK_REALTIME, &start_time); + for (int i = 0; i < 10 * 1024; i++) { + tf_ssb_append_post(ssb0, "Hello, world!"); + } + clock_gettime(CLOCK_REALTIME, &end_time); + printf("delta = %f seconds\n", (float)(end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec - start_time.tv_nsec) / 1e9f); + + uv_run(&loop, UV_RUN_DEFAULT); + + tf_ssb_destroy(ssb0); + + uv_loop_close(&loop); + + sqlite3_close(db0); +} diff --git a/src/ssb.tests.h b/src/ssb.tests.h index 631ec754..76cf063d 100644 --- a/src/ssb.tests.h +++ b/src/ssb.tests.h @@ -6,3 +6,4 @@ void tf_ssb_test_id_conversion(const tf_test_options_t* options); void tf_ssb_test_ssb(const tf_test_options_t* options); void tf_ssb_test_following(const tf_test_options_t* options); void tf_ssb_test_rooms(const tf_test_options_t* options); +void tf_ssb_test_bench(const tf_test_options_t* options); diff --git a/src/tests.c b/src/tests.c index ffb573ad..2f0d0647 100644 --- a/src/tests.c +++ b/src/tests.c @@ -697,5 +697,6 @@ void tf_tests(const tf_test_options_t* options) _tf_test_run(options, "sign", _test_sign); _tf_test_run(options, "b64", _test_b64); _tf_test_run(options, "rooms", tf_ssb_test_rooms); + _tf_test_run(options, "bench", tf_ssb_test_bench); printf("Tests completed.\n"); }