File: main.c

package info (click to toggle)
raft 0.22.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,504 kB
  • sloc: ansic: 37,539; makefile: 264; sh: 77; python: 22
file content (72 lines) | stat: -rw-r--r-- 1,409 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <assert.h>
#include <stdio.h>
#include <string.h>

#include "disk.h"
#include "report.h"
#include "submit.h"

enum {
    BENCHMARK_DISK = 0,
    BENCHMARK_SUBMIT,
};

static const char *doc =
    "benchmarks:\n"
    " - disk: Sequential disk writes\n"
    " - submit: Sequential submission of entries\n";

static const char *benchmarks[] =
    {[BENCHMARK_DISK] = "disk", [BENCHMARK_SUBMIT] = "submit", NULL};

int benchmarkCode(const char *name)
{
    int i = 0;
    while (benchmarks[i] != NULL) {
        if (strcmp(benchmarks[i], name) == 0) {
            return i;
        }
        i++;
    }
    return -1;
}

int main(int argc, char *argv[])
{
    struct report report;
    int cmd;
    int rv;

    assert(argc >= 1);

    if (argc < 2) {
        printf("usage: %s <benchmark> [--help | <args>]\n\n%s", argv[0], doc);
        return -1;
    }

    cmd = benchmarkCode(argv[1]);
    if (cmd == -1) {
        printf("unknown: benchmark '%s'\n", argv[1]);
        return -1;
    }

    ReportInit(&report);

    switch (cmd) {
        case BENCHMARK_DISK:
            rv = DiskRun(argc - 1, &argv[1], &report);
            break;
        case BENCHMARK_SUBMIT:
            rv = SubmitRun(argc - 1, &argv[1], &report);
            break;
        default:
            assert(0);
            rv = -1;
            break;
    }

    ReportPrint(&report);
    ReportClose(&report);

    return rv;
}