Skip to content

Commit

Permalink
Edit ministat to deal with map_delete crashing
Browse files Browse the repository at this point in the history
Example:

    BENCHMARK(2,
        foo_a();
        TIMED("B" foo_b();)
        TIMED("C" foo_c();)
        )

    Original execution sequence:
        foo_a, foo_b, foo_b, foo_c, foo_c

    New execution sequecne:
        foo_a, foo_b, foo_c, foo_a, foo_b, foo_c
  • Loading branch information
EagleTw committed Mar 20, 2023
1 parent ebc730c commit 32d4da1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 73 deletions.
66 changes: 2 additions & 64 deletions map/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,69 +18,7 @@ void swap(int *x, int *y)

enum { NNODES = 1000 * 1000 };

#if 0
int main()
{
printf("--- Self benchmark: map ---\n");

map_t tree = map_init(int, int, map_cmp_int);

int key[NNODES];
int val[NNODES];

/*
* Generate data for insertion
*/
for (int i = 0; i < NNODES; i++) {
key[i] = i;
val[i] = i;
}

/* This is not a reconmended way to randomize stuff, just a simple test */
/* I know MT19937 might be better */
srand((unsigned) time(NULL));
for (int i = 0; i < 1e7; i++) {
int pos_a = rand() % NNODES;
int pos_b = rand() % NNODES;
swap(&key[pos_a], &key[pos_b]);
swap(&val[pos_a], &val[pos_b]);
}

/*
* Insertion clcoking
*/
clock_t start = clock();
for (int i = 0; i < NNODES; i++) {
map_insert(tree, key + i, val + i);
}
printf(" tree_insert time: %f, seconds\n",
(double) (clock() - start) / CLOCKS_PER_SEC);

/*
* Seaching clcoking
*/
start = clock();
map_iter_t my_it;
for (int i = 0; i < NNODES; i++) {
map_find(tree, &my_it, key + i);
}
printf(" tree_find time: %f, seconds\n",
(double) (clock() - start) / CLOCKS_PER_SEC);

/*
* Deletion clcoking
*/
start = clock();
map_delete(tree);
printf(" tree_delete time: %f, seconds\n",
(double) (clock() - start) / CLOCKS_PER_SEC);

return 0;
}
#endif

BENCHMARK(
3,
BENCHMARK(20,

map_t tree = map_init(int, int, map_cmp_int);

Expand Down Expand Up @@ -114,5 +52,5 @@ BENCHMARK(
for (int i = 0; i < NNODES; i++) { map_find(tree, &my_it, key + i); });

/* There will be a funny behavior with delete */
// TIMED("map_delete", map_delete(tree););
TIMED("map_delete", map_delete(tree););
)
19 changes: 10 additions & 9 deletions map/src/minibench.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
printf("======= Ministat report ======\n"); \
double results[MAX_TESTS][N]; \
const char *names[MAX_TESTS]; \
__VA_ARGS__ \
for (int i=0; i<2; i++) { \
tests = -1; \
__VA_ARGS__ \
} \
ministat(2, tests+1, N, results, names); \
return 0; \
}
Expand All @@ -35,12 +38,10 @@
struct timespec before; \
struct timespec after; \
names[tests] = name; \
for (int i=0; i<N; i++) { \
clock_gettime(CLOCK_MONOTONIC, &before); \
__VA_ARGS__ \
clock_gettime(CLOCK_MONOTONIC, &after); \
results[tests][i] = \
(after.tv_sec - before.tv_sec)*1000000000UL \
+ (after.tv_nsec - before.tv_nsec); \
} \
clock_gettime(CLOCK_MONOTONIC, &before); \
__VA_ARGS__ \
clock_gettime(CLOCK_MONOTONIC, &after); \
results[tests][i] = \
(after.tv_sec - before.tv_sec)*1000000000UL \
+ (after.tv_nsec - before.tv_nsec); \
}

0 comments on commit 32d4da1

Please sign in to comment.