summaryrefslogtreecommitdiffstats
path: root/runtime/bench2/itest.c
diff options
context:
space:
mode:
authorhunt <hunt>2006-03-09 08:48:06 +0000
committerhunt <hunt>2006-03-09 08:48:06 +0000
commit68642a15584f9e4fbf8cfc5765a3cfaeac0a5bbb (patch)
tree456b5d73292446a4017fcecf5162e5b20be86e95 /runtime/bench2/itest.c
parent43efac911763c31250e953fcd633d7f275d88270 (diff)
downloadsystemtap-steved-68642a15584f9e4fbf8cfc5765a3cfaeac0a5bbb.tar.gz
systemtap-steved-68642a15584f9e4fbf8cfc5765a3cfaeac0a5bbb.tar.xz
systemtap-steved-68642a15584f9e4fbf8cfc5765a3cfaeac0a5bbb.zip
2006-03-09 Martin Hunt <hunt@redhat.com>
* bench2: New directory containing a benchmark framework.
Diffstat (limited to 'runtime/bench2/itest.c')
-rw-r--r--runtime/bench2/itest.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/runtime/bench2/itest.c b/runtime/bench2/itest.c
new file mode 100644
index 00000000..dc385567
--- /dev/null
+++ b/runtime/bench2/itest.c
@@ -0,0 +1,59 @@
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/time.h>
+#include <stdlib.h>
+#include <sys/resource.h>
+#include <unistd.h>
+
+typedef unsigned long long uint64;
+struct timeval tstart, tstop;
+
+void start()
+{
+ gettimeofday (&tstart, NULL);
+}
+
+uint64 usecs (struct timeval *tv)
+{
+ return tv->tv_sec * 1000000 + tv->tv_usec;
+}
+
+uint64 stop()
+{
+ gettimeofday (&tstop, NULL);
+ return usecs(&tstop) - usecs(&tstart);
+}
+
+void usage(char *name)
+{
+ printf ("Usage %s [time]\nWhere \"time\" is millions of times to loop.\n", name);
+ exit(1);
+}
+
+int main(int argc, char *argv[])
+{
+ int i, n = 1;
+ uint64 nsecs;
+
+ if (argc > 2)
+ usage(argv[0]);
+
+ if (argc == 2) {
+ n = strtol(argv[1], NULL, 10);
+ if (n == 0)
+ usage(argv[0]);
+ }
+
+
+ start();
+ for (i = 0; i < n * 1000000; i++)
+ getuid();
+
+ nsecs = stop() / (n * 1000);
+
+ /* returns nanosecs per call */
+ printf("%lld\n", nsecs);
+ return 0;
+}