100 lines
No EOL
2.7 KiB
C
100 lines
No EOL
2.7 KiB
C
#include <inttypes.h>
|
|
|
|
static int64_t accumulator = 0;
|
|
|
|
#define ITERS 1000000000
|
|
|
|
int64_t reset(int64_t val) {
|
|
int64_t temp = accumulator;
|
|
accumulator = val;
|
|
return temp;
|
|
}
|
|
|
|
__attribute__((noinline)) int64_t one(int64_t a) {
|
|
accumulator += a;
|
|
return accumulator;
|
|
}
|
|
|
|
__attribute__((noinline)) int64_t two(int64_t a, int64_t b) {
|
|
accumulator += a;
|
|
accumulator += b;
|
|
return accumulator;
|
|
}
|
|
|
|
__attribute__((noinline)) int64_t three(int64_t a, int64_t b, int64_t c) {
|
|
accumulator += a;
|
|
accumulator += b;
|
|
accumulator += c;
|
|
return accumulator;
|
|
}
|
|
|
|
__attribute__((noinline)) int64_t four(int64_t a, int64_t b, int64_t c, int64_t d) {
|
|
accumulator += a;
|
|
accumulator += b;
|
|
accumulator += c;
|
|
accumulator += d;
|
|
return accumulator;
|
|
}
|
|
|
|
__attribute__((noinline)) int64_t five(int64_t a, int64_t b, int64_t c, int64_t d, int64_t e) {
|
|
accumulator += a;
|
|
accumulator += b;
|
|
accumulator += c;
|
|
accumulator += d;
|
|
accumulator += e;
|
|
return accumulator;
|
|
}
|
|
|
|
__attribute__((noinline)) int64_t six(int64_t a, int64_t b, int64_t c, int64_t d, int64_t e, int64_t f) {
|
|
accumulator += a;
|
|
accumulator += b;
|
|
accumulator += c;
|
|
accumulator += d;
|
|
accumulator += e;
|
|
accumulator += f;
|
|
return accumulator;
|
|
}
|
|
|
|
__attribute__((noinline)) int64_t seven(int64_t a, int64_t b, int64_t c, int64_t d, int64_t e, int64_t f, int64_t g) {
|
|
accumulator += a;
|
|
accumulator += b;
|
|
accumulator += c;
|
|
accumulator += d;
|
|
accumulator += e;
|
|
accumulator += f;
|
|
accumulator += g;
|
|
return accumulator;
|
|
}
|
|
|
|
__attribute__((noinline)) int64_t eight(int64_t a, int64_t b, int64_t c, int64_t d, int64_t e, int64_t f, int64_t g, int64_t h) {
|
|
accumulator += a;
|
|
accumulator += b;
|
|
accumulator += c;
|
|
accumulator += d;
|
|
accumulator += e;
|
|
accumulator += f;
|
|
accumulator += g;
|
|
accumulator += h;
|
|
return accumulator;
|
|
}
|
|
|
|
#define BENCH(func, args) \
|
|
int64_t bench_##func(void) { \
|
|
for (int64_t i = 0; i < ITERS; i++) { \
|
|
func args; \
|
|
} \
|
|
return accumulator; \
|
|
}
|
|
|
|
BENCH(one, (accumulator))
|
|
BENCH(two, (accumulator, accumulator))
|
|
BENCH(three, (accumulator, accumulator, accumulator))
|
|
BENCH(four, (accumulator, accumulator, accumulator, accumulator))
|
|
BENCH(five, (accumulator, accumulator, accumulator, accumulator, accumulator))
|
|
BENCH(six, (accumulator, accumulator, accumulator, accumulator, accumulator, accumulator))
|
|
BENCH(seven, (accumulator, accumulator, accumulator, accumulator, accumulator, accumulator, accumulator))
|
|
BENCH(eight, (accumulator, accumulator, accumulator, accumulator, accumulator, accumulator, accumulator, accumulator))
|
|
|
|
int main(int argc, const char **argv) {
|
|
return 0;
|
|
} |