Example #1
0
void case_buf_puts(struct bench_ctx *ctx) {
    struct buf *buf = buf(NULL);
    int i;
    bench_ctx_reset_start_at(ctx);
    for (i = 0; i < ctx->n; i++) {
        buf_puts(buf, "abcdefg");
    }
    bench_ctx_reset_end_at(ctx);
    buf_free(buf);
}
Example #2
0
void
case_heap_push(struct bench_ctx *ctx)
{
    struct heap *heap = heap(&heap_bench_cmp);
    int i;
    bench_ctx_reset_start_at(ctx);
    for (i = 0; i < ctx->n; i++) {
        heap_push(heap, &i);
    }
    bench_ctx_reset_end_at(ctx);
    heap_free(heap);
}
Example #3
0
void
case_map_set(struct bench_ctx *ctx)
{
    struct map *m = map();
    /* keys suite */
    int i;
    char keys[ctx->n][4];
    for (i = 0; i < ctx->n; i++)
        sprintf(keys[i], "%d", i & 999);
    /* bench */
    bench_ctx_reset_start_at(ctx);
    for (i = 0; i < ctx->n; i++) {
        map_set(m, keys[i], "val");
    }
    bench_ctx_reset_end_at(ctx);
    map_free(m);
}
Example #4
0
void
case_dict_set(struct bench_ctx *ctx)
{
    struct dict *dict = dict();
    /* keys suite */
    int i;
    char keys[ctx->n][4];
    for (i = 0; i < ctx->n; i++)
        sprintf(keys[i], "%d", i & 999);
    /* bench */
    bench_ctx_reset_start_at(ctx);
    for (i = 0; i < ctx->n; i++) {
        dict_set(dict, keys[i], "val");
    }
    bench_ctx_reset_end_at(ctx);
    dict_free(dict);
}
Example #5
0
void
case_strings_search(struct bench_ctx *ctx)
{
    /* suite */
    int i;
    char strs[ctx->n][32];
    char subs[ctx->n][4];
    for (i = 0; i < ctx->n; i++) {
        sprintf(strs[i], "%d", i);
        sprintf(subs[i], "%d", i & 999);
    }
    /* bench */
    bench_ctx_reset_start_at(ctx);
    for (i = 0; i < ctx->n; i++) {
        strings_search(strs[i], subs[i], 0);
    }
    bench_ctx_reset_end_at(ctx);
}
Example #6
0
void
case_strings_replace(struct bench_ctx *ctx)
{
    /* suite */
    int i;
    char strs[ctx->n][32];
    char subs[ctx->n][4];
    for (i = 0; i < ctx->n; i++) {
        sprintf(strs[i], "%d", i);
        sprintf(subs[i], "%d", i & 999);
    }
    /* bench */
    bench_ctx_reset_start_at(ctx);
    for (i = 0; i < ctx->n; i++) {
        char dst[100];
        strings_replace(dst, strs[i], subs[i], "rep");
    }
    bench_ctx_reset_end_at(ctx);
}