summaryrefslogtreecommitdiffstats
path: root/tests/simple.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-09-17 03:18:51 +0000
committerTavian Barnes <tavianator@gmail.com>2009-09-17 03:18:51 +0000
commit66084b816dd25a41f774240328a31d57efd276e4 (patch)
treeacd22d0e3eb5f5608184fc18479e8890906cbe7f /tests/simple.c
parentf46ea7eb1b6f55036f10b6ae919c1785cb72c836 (diff)
downloadlibsandglass-66084b816dd25a41f774240328a31d57efd276e4.tar.xz
Begin libsandglass implementation.
Diffstat (limited to 'tests/simple.c')
-rw-r--r--tests/simple.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/simple.c b/tests/simple.c
index 921ab6c..85dacb6 100644
--- a/tests/simple.c
+++ b/tests/simple.c
@@ -19,10 +19,37 @@
*************************************************************************/
#include <sandglass.h>
+#include <unistd.h>
+#include <time.h>
#include <stdlib.h>
+#include <stdio.h>
int
main()
{
+ sandglass_t sandglass;
+ sandglass_attributes_t min = { SANDGLASS_MONOTONIC, SANDGLASS_SYSTEM },
+ max = { SANDGLASS_MONOTONIC, SANDGLASS_CPUTIME };
+ struct timespec tosleep = { .tv_sec = 0, .tv_nsec = 100000000 };
+
+ if (sandglass_create(&sandglass, &min, &max) != 0) {
+ perror("sandglass_create()");
+ return EXIT_FAILURE;
+ }
+
+ if (sandglass_begin(&sandglass) != 0) {
+ perror("sandglass_begin()");
+ return EXIT_FAILURE;
+ }
+ while (nanosleep(&tosleep, &tosleep) != 0);
+ if (sandglass_elapse(&sandglass) != 0) {
+ perror("sandglass_elapse()");
+ return EXIT_FAILURE;
+ }
+
+ printf("0.1 seconds timed by sandglass as %ld grains; %g s\n",
+ sandglass.grains,
+ sandglass.grains/sandglass.resolution);
+
return EXIT_SUCCESS;
}