2 * Copyright 2008, Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 extern void __nacl_null(void);
45 int num_rep
= 10000000;
47 struct timeval time_start
;
48 struct timeval time_end
;
49 struct timeval time_elapsed
;
52 while (EOF
!= (opt
= getopt(ac
, av
, "r:"))) switch (opt
) {
54 num_rep
= strtol(optarg
, (char **) NULL
, 0);
57 fprintf(stderr
, "Usage: null [-r repetition_count]\n");
60 gettimeofday(&time_start
, (void *) NULL
);
61 for (i
= num_rep
; --i
>= 0; ) {
64 gettimeofday(&time_end
, (void *) NULL
);
65 time_elapsed
.tv_sec
= time_end
.tv_sec
- time_start
.tv_sec
;
66 time_elapsed
.tv_usec
= time_end
.tv_usec
- time_start
.tv_usec
;
67 if (time_elapsed
.tv_usec
< 0) {
68 --time_elapsed
.tv_sec
;
69 time_elapsed
.tv_usec
+= 1000000;
71 printf("Number of null syscalls: %d\n", num_rep
);
72 printf("Elapsed time: %d.%06dS\n",
73 (int) time_elapsed
.tv_sec
,
74 (int) time_elapsed
.tv_usec
);
75 time_per_call
= ((time_elapsed
.tv_sec
+ time_elapsed
.tv_usec
/ 1.0e6
)
77 printf("Time per call: %gS or %fnS\n",
79 1.0e9
* time_per_call
);
80 printf("Calls per sec: %d\n", (int) (1.0 / time_per_call
));