main
test-branch
|
Last change
on this file since 1aaefd4 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago |
|
Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.
git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c
|
-
Property mode
set to
100644
|
|
File size:
1.0 KB
|
| Line | |
|---|
| 1 | #include "time.h"
|
|---|
| 2 | #include "math.h"
|
|---|
| 3 | #include "stdio.h"
|
|---|
| 4 | #include "cclock.h"
|
|---|
| 5 |
|
|---|
| 6 | /*
|
|---|
| 7 | A small helper function to manipulate accurate times (on LINUX).
|
|---|
| 8 |
|
|---|
| 9 | Do not forget to add -lrt at link time
|
|---|
| 10 | (C) G. Colin de Verdiere, CEA.
|
|---|
| 11 |
|
|---|
| 12 | */
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 | void
|
|---|
| 16 | psecs(struct timespec start) {
|
|---|
| 17 | printf("(%ld %ld)\n", start.tv_sec, start.tv_nsec);
|
|---|
| 18 | }
|
|---|
| 19 |
|
|---|
| 20 | double
|
|---|
| 21 | tseconde(struct timespec start) {
|
|---|
| 22 | return (double) start.tv_sec + (double) 1e-9 *(double) start.tv_nsec;
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | double
|
|---|
| 26 | dcclock(void) {
|
|---|
| 27 | return tseconde(cclock());
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | double
|
|---|
| 31 | ccelaps(struct timespec start, struct timespec end) {
|
|---|
| 32 | double ds = end.tv_sec - start.tv_sec;
|
|---|
| 33 | double dns = end.tv_nsec - start.tv_nsec;
|
|---|
| 34 | if (dns < 0) {
|
|---|
| 35 | // wrap around will occur in the nanosec part. Compensate this.
|
|---|
| 36 | dns = 1e9 + end.tv_nsec - start.tv_nsec;
|
|---|
| 37 | ds = ds - 1;
|
|---|
| 38 | }
|
|---|
| 39 | double telaps = ds + dns * 1e-9;
|
|---|
| 40 | return telaps;
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | struct timespec
|
|---|
| 44 | cclock(void) {
|
|---|
| 45 | struct timespec tstart;
|
|---|
| 46 | clockid_t cid = CLOCK_REALTIME;
|
|---|
| 47 | int status = 0;
|
|---|
| 48 |
|
|---|
| 49 | status = clock_gettime(cid, &tstart);
|
|---|
| 50 | return tstart;
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | //
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.