Minor fixes on top of patch from rocco@tecsiel.it:
Hi Rusty,
latest git version of the file ccan/jmap/tools/speed.c does not
compile.
Please find attacched my own version with the following differences:
1. deleted inclusion of <ccan/jmap/jmap_type.h> which is no longer in ccan/
2. added inclusion of <ccan/time/time.h>
3. added definition of struct jmap_obj in terms of JMAP_MEMBERS();
4. deleted use of macro JMAP_DEFINE_UINTIDX_TYPE() which is no longer needed
5. changed function normalize() to be aligned with ccan/htable/tools/speed.c
6. repleaced gettimeofday() in favour of time_now()
7. added memory cleanup at the end of the program in terms of
jmap_free(jmap);
free(objs);
to be valgrind safe
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
CFLAGS=-Wall -Werror -O3 -I../../..
CFLAGS=-Wall -Werror -O3 -I../../..
-speed.o: speed.c ../jmap.h ../jmap_type.h ../jmap.c
+speed.o: speed.c ../jmap.h
/* Simple speed tests for jmap. */
/* Simple speed tests for jmap. */
-#include <ccan/jmap/jmap_type.h>
#include <ccan/jmap/jmap.c>
#include <ccan/jmap/jmap.c>
+#include <ccan/time/time.c>
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
struct object {
/* Some contents. Doubles as consistency check. */
struct object *self;
};
struct object {
/* Some contents. Doubles as consistency check. */
struct object *self;
};
+struct jmap_obj {
+ JMAP_MEMBERS(unsigned int, struct object *);
+};
+
/* Nanoseconds per operation */
/* Nanoseconds per operation */
-static size_t normalize(const struct timeval *start,
- const struct timeval *stop,
+static size_t normalize(const struct timeabs *start,
+ const struct timeabs *stop,
- struct timeval diff;
-
- timersub(stop, start, &diff);
-
- /* Floating point is more accurate here. */
- return (double)(diff.tv_sec * 1000000 + diff.tv_usec)
- / num * 1000;
+ return time_to_nsec(time_divide(time_between(*stop, *start), num));
-JMAP_DEFINE_UINTIDX_TYPE(struct object, obj);
-
int main(int argc, char *argv[])
{
struct object *objs;
int main(int argc, char *argv[])
{
struct object *objs;
- size_t i, j, num;
- struct timeval start, stop;
+ unsigned int i, j;
+ size_t num;
+ struct timeabs start, stop;
struct jmap_obj *jmap;
num = argv[1] ? atoi(argv[1]) : 1000000;
struct jmap_obj *jmap;
num = argv[1] ? atoi(argv[1]) : 1000000;
objs[i].self = &objs[i];
}
objs[i].self = &objs[i];
}
+ jmap = jmap_new(struct jmap_obj);
printf("Initial insert: ");
fflush(stdout);
printf("Initial insert: ");
fflush(stdout);
- gettimeofday(&start, NULL);
for (i = 0; i < num; i++)
for (i = 0; i < num; i++)
- jmap_obj_add(jmap, i, objs[i].self);
- gettimeofday(&stop, NULL);
+ jmap_add(jmap, i, objs[i].self);
+ stop = time_now();
printf(" %zu ns\n", normalize(&start, &stop, num));
printf("Initial lookup (match): ");
fflush(stdout);
printf(" %zu ns\n", normalize(&start, &stop, num));
printf("Initial lookup (match): ");
fflush(stdout);
- gettimeofday(&start, NULL);
for (i = 0; i < num; i++)
for (i = 0; i < num; i++)
- if (jmap_obj_get(jmap, i)->self != objs[i].self)
+ if (jmap_get(jmap, i)->self != objs[i].self)
- gettimeofday(&stop, NULL);
printf(" %zu ns\n", normalize(&start, &stop, num));
printf("Initial lookup (miss): ");
fflush(stdout);
printf(" %zu ns\n", normalize(&start, &stop, num));
printf("Initial lookup (miss): ");
fflush(stdout);
- gettimeofday(&start, NULL);
for (i = 0; i < num; i++)
for (i = 0; i < num; i++)
- if (jmap_obj_get(jmap, i+num))
+ if (jmap_get(jmap, i+num))
- gettimeofday(&stop, NULL);
printf(" %zu ns\n", normalize(&start, &stop, num));
/* Lookups in order are very cache-friendly for judy; try random */
printf("Initial lookup (random): ");
fflush(stdout);
printf(" %zu ns\n", normalize(&start, &stop, num));
/* Lookups in order are very cache-friendly for judy; try random */
printf("Initial lookup (random): ");
fflush(stdout);
- gettimeofday(&start, NULL);
for (i = 0, j = 0; i < num; i++, j = (j + 10007) % num)
for (i = 0, j = 0; i < num; i++, j = (j + 10007) % num)
- if (jmap_obj_get(jmap, j)->self != &objs[j])
+ if (jmap_get(jmap, j)->self != &objs[j])
- gettimeofday(&stop, NULL);
printf(" %zu ns\n", normalize(&start, &stop, num));
printf("Initial delete all: ");
fflush(stdout);
printf(" %zu ns\n", normalize(&start, &stop, num));
printf("Initial delete all: ");
fflush(stdout);
- gettimeofday(&start, NULL);
for (i = 0; i < num; i++)
for (i = 0; i < num; i++)
- jmap_obj_del(jmap, i);
- gettimeofday(&stop, NULL);
+ jmap_del(jmap, i);
+ stop = time_now();
printf(" %zu ns\n", normalize(&start, &stop, num));
printf("Initial re-inserting: ");
fflush(stdout);
printf(" %zu ns\n", normalize(&start, &stop, num));
printf("Initial re-inserting: ");
fflush(stdout);
- gettimeofday(&start, NULL);
for (i = 0; i < num; i++)
for (i = 0; i < num; i++)
- jmap_obj_add(jmap, i, objs[i].self);
- gettimeofday(&stop, NULL);
+ jmap_add(jmap, i, objs[i].self);
+ stop = time_now();
printf(" %zu ns\n", normalize(&start, &stop, num));
printf("Deleting first half: ");
fflush(stdout);
printf(" %zu ns\n", normalize(&start, &stop, num));
printf("Deleting first half: ");
fflush(stdout);
- gettimeofday(&start, NULL);
for (i = 0; i < num; i+=2)
for (i = 0; i < num; i+=2)
- jmap_obj_del(jmap, i);
- gettimeofday(&stop, NULL);
+ jmap_del(jmap, i);
+ stop = time_now();
printf(" %zu ns\n", normalize(&start, &stop, num));
printf("Adding (a different) half: ");
fflush(stdout);
printf(" %zu ns\n", normalize(&start, &stop, num));
printf("Adding (a different) half: ");
fflush(stdout);
- gettimeofday(&start, NULL);
for (i = 0; i < num; i+=2)
for (i = 0; i < num; i+=2)
- jmap_obj_add(jmap, num+i, objs[i].self);
- gettimeofday(&stop, NULL);
+ jmap_add(jmap, num+i, objs[i].self);
+ stop = time_now();
printf(" %zu ns\n", normalize(&start, &stop, num));
printf("Lookup after half-change (match): ");
fflush(stdout);
printf(" %zu ns\n", normalize(&start, &stop, num));
printf("Lookup after half-change (match): ");
fflush(stdout);
- gettimeofday(&start, NULL);
for (i = 1; i < num; i+=2)
for (i = 1; i < num; i+=2)
- if (jmap_obj_get(jmap, i)->self != objs[i].self)
+ if (jmap_get(jmap, i)->self != objs[i].self)
abort();
for (i = 0; i < num; i+=2)
abort();
for (i = 0; i < num; i+=2)
- if (jmap_obj_get(jmap, i+num)->self != objs[i].self)
+ if (jmap_get(jmap, i+num)->self != objs[i].self)
- gettimeofday(&stop, NULL);
printf(" %zu ns\n", normalize(&start, &stop, num));
printf("Lookup after half-change(miss): ");
fflush(stdout);
printf(" %zu ns\n", normalize(&start, &stop, num));
printf("Lookup after half-change(miss): ");
fflush(stdout);
- gettimeofday(&start, NULL);
for (i = 0; i < num; i++)
for (i = 0; i < num; i++)
- if (jmap_obj_get(jmap, i+num*2))
+ if (jmap_get(jmap, i+num*2))
- gettimeofday(&stop, NULL);
printf(" %zu ns\n", normalize(&start, &stop, num));
/* Hashtables with delete markers can fill with markers over time.
* so do some changes to see how it operates in long-term. */
printf("Details: churning first time\n");
for (i = 1; i < num; i+=2) {
printf(" %zu ns\n", normalize(&start, &stop, num));
/* Hashtables with delete markers can fill with markers over time.
* so do some changes to see how it operates in long-term. */
printf("Details: churning first time\n");
for (i = 1; i < num; i+=2) {
- if (!jmap_obj_del(jmap, i))
+ if (!jmap_del(jmap, i))
- jmap_obj_add(jmap, i, objs[i].self);
+ jmap_add(jmap, i, objs[i].self);
}
for (i = 0; i < num; i+=2) {
}
for (i = 0; i < num; i+=2) {
- if (!jmap_obj_del(jmap, i+num))
+ if (!jmap_del(jmap, i+num))
- jmap_obj_add(jmap, i, objs[i].self);
+ jmap_add(jmap, i, objs[i].self);
}
for (i = 1; i < 5; i++) {
printf("Churning %s time: ",
}
for (i = 1; i < 5; i++) {
printf("Churning %s time: ",
: i == 3 ? "fourth"
: "fifth");
fflush(stdout);
: i == 3 ? "fourth"
: "fifth");
fflush(stdout);
- gettimeofday(&start, NULL);
for (j = 0; j < num; j++) {
for (j = 0; j < num; j++) {
- if (!jmap_obj_del(jmap, num*(i-1)+j))
+ if (!jmap_del(jmap, num*(i-1)+j))
- jmap_obj_add(jmap, num*i+j, &objs[j]);
+ jmap_add(jmap, num*i+j, &objs[j]);
- gettimeofday(&stop, NULL);
printf(" %zu ns\n", normalize(&start, &stop, num));
}
/* Spread out the keys more to try to make it harder. */
printf("Details: reinserting with spread\n");
for (i = 0; i < num; i++) {
printf(" %zu ns\n", normalize(&start, &stop, num));
}
/* Spread out the keys more to try to make it harder. */
printf("Details: reinserting with spread\n");
for (i = 0; i < num; i++) {
- if (!jmap_obj_del(jmap, num*4 + i))
+ if (!jmap_del(jmap, num*4 + i))
- jmap_obj_add(jmap, num * 5 + i * 9, objs[i].self);
+ jmap_add(jmap, num * 5 + i * 9, objs[i].self);
- if (jmap_obj_popcount(jmap, 0, -1) != num)
+ if (jmap_popcount(jmap, 0, -1) != num)
abort();
printf("Lookup after churn & spread (match): ");
fflush(stdout);
abort();
printf("Lookup after churn & spread (match): ");
fflush(stdout);
- gettimeofday(&start, NULL);
for (i = 0; i < num; i++)
for (i = 0; i < num; i++)
- if (jmap_obj_get(jmap, num * 5 + i * 9)->self != objs[i].self) {
+ if (jmap_get(jmap, num * 5 + i * 9)->self != objs[i].self) {
printf("i =%u\n", i);
abort();
}
printf("i =%u\n", i);
abort();
}
- gettimeofday(&stop, NULL);
printf(" %zu ns\n", normalize(&start, &stop, num));
printf("Lookup after churn & spread (miss): ");
fflush(stdout);
printf(" %zu ns\n", normalize(&start, &stop, num));
printf("Lookup after churn & spread (miss): ");
fflush(stdout);
- gettimeofday(&start, NULL);
for (i = 0; i < num; i++)
for (i = 0; i < num; i++)
- if (jmap_obj_get(jmap, num * 6 + i * 9))
+ if (jmap_get(jmap, num * 6 + i * 9))
- gettimeofday(&stop, NULL);
printf(" %zu ns\n", normalize(&start, &stop, num));
printf("Lookup after churn & spread (random): ");
fflush(stdout);
printf(" %zu ns\n", normalize(&start, &stop, num));
printf("Lookup after churn & spread (random): ");
fflush(stdout);
- gettimeofday(&start, NULL);
for (i = 0, j = 0; i < num; i++, j = (j + 10007) % num)
for (i = 0, j = 0; i < num; i++, j = (j + 10007) % num)
- if (jmap_obj_get(jmap, num * 5 + j * 9)->self != &objs[j])
+ if (jmap_get(jmap, num * 5 + j * 9)->self != &objs[j])
- gettimeofday(&stop, NULL);
printf(" %zu ns\n", normalize(&start, &stop, num));
printf("Lookup after churn & spread (half-random): ");
fflush(stdout);
printf(" %zu ns\n", normalize(&start, &stop, num));
printf("Lookup after churn & spread (half-random): ");
fflush(stdout);
- gettimeofday(&start, NULL);
for (i = 0, j = 0; i < num/2; i++, j = (j + 10007) % num) {
for (i = 0, j = 0; i < num/2; i++, j = (j + 10007) % num) {
- if (jmap_obj_get(jmap, num * 5 + j * 9)->self != &objs[j])
+ if (jmap_get(jmap, num * 5 + j * 9)->self != &objs[j])
- if (jmap_obj_get(jmap, num * 5 + (j + 1) * 9)->self != &objs[j+1])
+ if (jmap_get(jmap, num * 5 + (j + 1) * 9)->self != &objs[j+1])
- gettimeofday(&stop, NULL);
printf(" %zu ns\n", normalize(&start, &stop, num));
printf("Deleting half after churn & spread: ");
fflush(stdout);
printf(" %zu ns\n", normalize(&start, &stop, num));
printf("Deleting half after churn & spread: ");
fflush(stdout);
- gettimeofday(&start, NULL);
for (i = 0; i < num; i+=2)
for (i = 0; i < num; i+=2)
- jmap_obj_del(jmap, num * 5 + i * 9);
- gettimeofday(&stop, NULL);
+ jmap_del(jmap, num * 5 + i * 9);
+ stop = time_now();
printf(" %zu ns\n", normalize(&start, &stop, num));
printf("Adding (a different) half after churn & spread: ");
fflush(stdout);
printf(" %zu ns\n", normalize(&start, &stop, num));
printf("Adding (a different) half after churn & spread: ");
fflush(stdout);
- gettimeofday(&start, NULL);
for (i = 0; i < num; i+=2)
for (i = 0; i < num; i+=2)
- jmap_obj_add(jmap, num * 6 + i * 9, objs[i].self);
- gettimeofday(&stop, NULL);
+ jmap_add(jmap, num * 6 + i * 9, objs[i].self);
+ stop = time_now();
printf(" %zu ns\n", normalize(&start, &stop, num));
printf(" %zu ns\n", normalize(&start, &stop, num));
+ jmap_free(jmap);
+ free (objs);
+