Skip to content

Commit

Permalink
benchmark: expose used namespace as CLI argument
Browse files Browse the repository at this point in the history
  • Loading branch information
tilpner committed Feb 25, 2021
1 parent be60653 commit 91d8cd2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 4 additions & 0 deletions benchmark/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ static gboolean opt_machine_readable = FALSE;
static gchar* opt_path = NULL;
static gchar* opt_semantics = NULL;
static gchar* opt_template = NULL;
static gchar* opt_namespace = NULL;

static JSemantics* j_benchmark_semantics = NULL;

Expand Down Expand Up @@ -115,6 +116,7 @@ j_benchmark_add(gchar const* name, BenchmarkFunc benchmark_func)
run->iterations = 0;
run->operations = 0;
run->bytes = 0;
run->namespace = opt_namespace ? opt_namespace : "benchmark";

j_benchmarks = g_list_prepend(j_benchmarks, run);
}
Expand Down Expand Up @@ -301,6 +303,7 @@ main(int argc, char** argv)
{ "path", 'p', 0, G_OPTION_ARG_STRING, &opt_path, "Benchmark path to use", NULL },
{ "semantics", 's', 0, G_OPTION_ARG_STRING, &opt_semantics, "Semantics to use", NULL },
{ "template", 't', 0, G_OPTION_ARG_STRING, &opt_template, "Semantics template to use", NULL },
{ "namespace", 'n', 0, G_OPTION_ARG_STRING, &opt_namespace, "Namespace for benchmark to use", NULL },
{ NULL, 0, 0, 0, NULL, NULL, NULL }
};

Expand Down Expand Up @@ -373,6 +376,7 @@ main(int argc, char** argv)
g_free(opt_path);
g_free(opt_semantics);
g_free(opt_template);
g_free(opt_namespace);

return 0;
}
2 changes: 2 additions & 0 deletions benchmark/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ struct BenchmarkRun
guint iterations;
guint64 operations;
guint64 bytes;

gchar* namespace;
};

typedef struct BenchmarkRun BenchmarkRun;
Expand Down
14 changes: 7 additions & 7 deletions benchmark/object/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ _benchmark_object_create(BenchmarkRun* run, gboolean use_batch)
g_autofree gchar* name = NULL;

name = g_strdup_printf("benchmark-%d", i);
object = j_object_new("benchmark", name);
object = j_object_new(run->namespace, name);
j_object_create(object, batch);

j_object_delete(object, delete_batch);
Expand Down Expand Up @@ -110,7 +110,7 @@ _benchmark_object_delete(BenchmarkRun* run, gboolean use_batch)
g_autofree gchar* name = NULL;

name = g_strdup_printf("benchmark-%d", i);
object = j_object_new("benchmark", name);
object = j_object_new(run->namespace, name);
j_object_create(object, batch);
}

Expand All @@ -125,7 +125,7 @@ _benchmark_object_delete(BenchmarkRun* run, gboolean use_batch)
g_autofree gchar* name = NULL;

name = g_strdup_printf("benchmark-%d", i);
object = j_object_new("benchmark", name);
object = j_object_new(run->namespace, name);

j_object_delete(object, batch);

Expand Down Expand Up @@ -178,7 +178,7 @@ _benchmark_object_status(BenchmarkRun* run, gboolean use_batch)
semantics = j_benchmark_get_semantics();
batch = j_batch_new(semantics);

object = j_object_new("benchmark", "benchmark");
object = j_object_new(run->namespace, "benchmark");
j_object_create(object, batch);
j_object_write(object, dummy, 1, 0, &size, batch);

Expand Down Expand Up @@ -245,7 +245,7 @@ _benchmark_object_read(BenchmarkRun* run, gboolean use_batch, guint block_size)
semantics = j_benchmark_get_semantics();
batch = j_batch_new(semantics);

object = j_object_new("benchmark", "benchmark");
object = j_object_new(run->namespace, "benchmark");
j_object_create(object, batch);

for (guint i = 0; i < n; i++)
Expand Down Expand Up @@ -320,7 +320,7 @@ _benchmark_object_write(BenchmarkRun* run, gboolean use_batch, guint block_size)
semantics = j_benchmark_get_semantics();
batch = j_batch_new(semantics);

object = j_object_new("benchmark", "benchmark");
object = j_object_new(run->namespace, "benchmark");
j_object_create(object, batch);
ret = j_batch_execute(batch);
g_assert_true(ret);
Expand Down Expand Up @@ -393,7 +393,7 @@ _benchmark_object_unordered_create_delete(BenchmarkRun* run, gboolean use_batch)
g_autofree gchar* name = NULL;

name = g_strdup_printf("benchmark-%d", i);
object = j_object_new("benchmark", name);
object = j_object_new(run->namespace, name);
j_object_create(object, batch);
j_object_delete(object, batch);

Expand Down

0 comments on commit 91d8cd2

Please sign in to comment.