int N;
static unsigned long long start;
-static unsigned long long ns;
+static unsigned long long dt;
//static unsigned long long bytes;
#define SEC 1000000000ULL
#define MAXN 1000000000
-static unsigned long long nsclock() {
+static unsigned long long tic() {
struct timespec ts;
- int r;
- r = clock_gettime(CLOCK_MONOTONIC, &ts);
- if (r < 0) {
+ if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) {
fprintf(stderr, "bench: clock_gettime failed: %s\n", strerror(errno));
return 0;
}
void start_timer() {
if (!start)
- start = nsclock();
+ start = tic();
}
void stop_timer() {
if (start)
- ns += nsclock() - start;
+ dt += tic() - start;
start = 0;
}
void reset_timer() {
if (start)
- start = nsclock();
- ns = 0;
+ start = tic();
+ dt = 0;
}
static int nextN() {
- unsigned long long n = ns/N;
+ unsigned long long n = dt/N;
if (n)
n = SEC/n;
f();
stop_timer();
// fprintf(stderr, "%10d%12llu\n", N, ns);
- if (ns > SEC || N >= MAXN)
+ if (dt >= SEC || N >= MAXN)
break;
if (N <= 0) {
fprintf(stderr, "bench: fatal: N <= 0\n");
return;
}
}
- if (ns/N > 100)
- fprintf(stderr, "%10d%10llu ns/op\n", N, ns/N);
+ if (dt/N > 100)
+ fprintf(stderr, "%10d%10llu ns/op\n", N, dt/N);
else
- fprintf(stderr, "%10d%13.2f ns/op\n", N, (double)ns/N);
+ fprintf(stderr, "%10d%13.2f ns/op\n", N, (double)dt/N);
}
int main() {
error("setenv: %s\n", strerror(errno));
if (strcmp(s=getenv("TEST"),"3") != 0)
error("getenv(\"TEST\"): \"%s\", wanted \"3\"\n", s);
+ /* test failures */
if ((r=setenv("","",0)) != -1 || errno != EINVAL)
- error("setenv(\"\",\"\"): %d, errno: %d (%s), wanted -1, %d (EINVAL)\n", r, errno, strerror(errno), EINVAL);
+ error("setenv(\"\",\"\",0): %d, errno: %d (%s), wanted -1, %d (EINVAL)\n", r, errno, strerror(errno), EINVAL);
+ if ((r=setenv(0,"",0)) != -1 || errno != EINVAL)
+ error("setenv(0,\"\",0): %d, errno: %d (%s), wanted -1, %d (EINVAL)\n", r, errno, strerror(errno), EINVAL);
}