Root/m1/perf/main.c

Source at commit c02c02903d5c91d5bd7a1a7faf982b4ae60afec2 created 8 years 1 month ago.
By Werner Almesberger, m1/perf/: a bunch of bug fixes all over the place
1#include <stdlib.h>
2#include <stdio.h>
3
4#include "compiler.h"
5
6
7#define BUF_SIZE 1000000
8
9
10static void report(const char *s)
11{
12    fprintf(stderr, "%s\n", s);
13}
14
15
16static void usage(const char *name)
17{
18    fprintf(stderr, "usage: %s patch-file [loops]\n", name);
19    exit(1);
20}
21
22
23int main(int argc, char **argv)
24{
25    char buf[BUF_SIZE];
26    const char *name;
27    FILE *file;
28    size_t got;
29    int loops = 1;
30    int i;
31
32    switch (argc) {
33    case 2:
34        break;
35    case 3:
36        loops = atoi(argv[2]);
37        break;
38    default:
39        usage(*argv);
40    }
41
42    name = argv[1];
43    file = fopen(name, "r");
44    if (!file) {
45        perror(name);
46        exit(1);
47    }
48    got = fread(buf, 1, sizeof(buf)-1, file);
49    if (got < 0) {
50        perror(name);
51        exit(1);
52    }
53    buf[got] = 0;
54    fclose(file);
55
56    for (i = 0; i != loops; i++)
57        patch_compile(buf, report);
58
59    return 0;
60}
61

Archive Download this file

Branches:
master



interactive