2a3abc
bench: renames, env: setenv(0,..) test
@@ -19,18 +19,16 @@ void error__(const char *n, int l, const char *s, ...) {
|
|
19
19
|
|
20
20
|
int N;
|
21
21
|
static unsigned long long start;
|
22
|
-
static unsigned long long
|
22
|
+
static unsigned long long dt;
|
23
23
|
//static unsigned long long bytes;
|
24
24
|
|
25
25
|
|
26
26
|
|
27
27
|
|
28
|
-
static unsigned long long
|
28
|
+
static unsigned long long tic() {
|
29
29
|
struct timespec ts;
|
30
|
-
int r;
|
31
30
|
|
32
|
-
|
31
|
+
if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) {
|
33
|
-
if (r < 0) {
|
34
32
|
fprintf(stderr, "bench: clock_gettime failed: %s\n", strerror(errno));
|
35
33
|
return 0;
|
36
34
|
}
|
@@ -39,23 +37,23 @@ static unsigned long long nsclock() {
|
|
39
37
|
|
40
38
|
void start_timer() {
|
41
39
|
if (!start)
|
42
|
-
start =
|
40
|
+
start = tic();
|
43
41
|
}
|
44
42
|
|
45
43
|
void stop_timer() {
|
46
44
|
if (start)
|
47
|
-
|
45
|
+
dt += tic() - start;
|
48
46
|
start = 0;
|
49
47
|
}
|
50
48
|
|
51
49
|
void reset_timer() {
|
52
50
|
if (start)
|
53
|
-
start =
|
54
|
-
|
51
|
+
start = tic();
|
52
|
+
dt = 0;
|
55
53
|
}
|
56
54
|
|
57
55
|
static int nextN() {
|
58
|
-
unsigned long long n =
|
56
|
+
unsigned long long n = dt/N;
|
59
57
|
|
60
58
|
if (n)
|
61
59
|
n = SEC/n;
|
@@ -79,17 +77,17 @@ static void run(const char *name, void (*f)()) {
|
|
79
77
|
f();
|
80
78
|
stop_timer();
|
81
79
|
// fprintf(stderr, "%10d%12llu\n", N, ns);
|
82
|
-
if (
|
80
|
+
if (dt >= SEC || N >= MAXN)
|
83
81
|
break;
|
84
82
|
if (N <= 0) {
|
85
83
|
fprintf(stderr, "bench: fatal: N <= 0\n");
|
86
84
|
return;
|
87
85
|
}
|
88
86
|
}
|
89
|
-
if (
|
90
|
-
fprintf(stderr, "%10d%10llu ns/op\n", N,
|
87
|
+
if (dt/N > 100)
|
88
|
+
fprintf(stderr, "%10d%10llu ns/op\n", N, dt/N);
|
91
89
|
else
|
92
|
-
fprintf(stderr, "%10d%13.2f ns/op\n", N, (double)
|
90
|
+
fprintf(stderr, "%10d%13.2f ns/op\n", N, (double)dt/N);
|
93
91
|
}
|
94
92
|
|
95
93
|
int main() {
|
@@ -40,6 +40,9 @@ void test_env() {
|
|
40
40
|
error("setenv: %s\n", strerror(errno));
|
41
41
|
if (strcmp(s=getenv("TEST"),"3") != 0)
|
42
42
|
error("getenv(\"TEST\"): \"%s\", wanted \"3\"\n", s);
|
43
|
+
/* test failures */
|
43
44
|
if ((r=setenv("","",0)) != -1 || errno != EINVAL)
|
44
|
-
error("setenv
|
45
|
+
error("setenv(\"\",\"\",0): %d, errno: %d (%s), wanted -1, %d (EINVAL)\n", r, errno, strerror(errno), EINVAL);
|
46
|
+
if ((r=setenv(0,"",0)) != -1 || errno != EINVAL)
|
47
|
+
error("setenv(0,\"\",0): %d, errno: %d (%s), wanted -1, %d (EINVAL)\n", r, errno, strerror(errno), EINVAL);
|
45
48
|
}
|