-#define _POSIX_C_SOURCE 200809L
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "test.h"
-#define T(t)
-#define B(t) void t();
-#include "main.h"
+#define T(f)
+#define B(f) void f(int);
+#include "tests.h"
#undef B
static int verbose = 1;
fprintf(stderr, "use error in tests only\n");
}
-int N;
+static int N;
static unsigned long long start;
static unsigned long long dt;
//static unsigned long long bytes;
static unsigned long long tic() {
struct timespec ts;
- if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) {
+ if (clock_gettime(CLOCK_REALTIME, &ts) < 0) {
fprintf(stderr, "bench: clock_gettime failed: %s\n", strerror(errno));
return 0;
}
static int nextN() {
unsigned long long n = dt/N;
+ unsigned long long i;
if (n)
n = SEC/2/n;
n = N+1;
if (n > MAXN)
n = MAXN;
- return n;
+
+ /* round up to a nice number */
+ for (i = 1; i < n; i *= 10);
+ if (i/2 >= n)
+ i /= 2;
+ if (i/2 >= n)
+ i /= 2;
+ return i;
}
void vmstats() {
f = fopen("/proc/self/smaps", "rb");
if (f) while (fgets(buf, sizeof buf, f)) {
- if (sscanf(buf, "%*lx-%*lx %*s %*lx %x:%x %*lu %*s", &maj, &min)==2)
+ if (sscanf(buf, "%*x-%*x %*s %*x %x:%x %*u %*s", &maj, &min)==2)
in_heap = (!maj && !min && !strstr(buf, "---p") && (strstr(buf, "[heap]") || !strchr(buf, '[')));
if (in_heap) {
if (sscanf(buf, "Size: %lu", &l)==1) vm_size += l;
fputc('\n', stderr);
}
-static void run(const char *name, void (*f)()) {
+static void run(const char *name, void (*f)(int)) {
int p = fork();
if (p) {
int s;
}
fprintf(stderr, "%-32s", name);
for (N=1; ; N=nextN()) {
+ // TODO: fork at each iteration and pass N,dt..?
reset_timer();
start_timer();
- f();
+ f(N);
stop_timer();
// fprintf(stderr, "%10d%12llu next: %d\n", N, dt, nextN());
if (dt >= SEC/2 || N >= MAXN) {
int main() {
#define B(t) run(#t, t);
-#include "main.h"
+#include "tests.h"
return 0;
}