COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
old/sensors/imu_microstrain/clock_test.cpp File Reference
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <sys/time.h>
Include dependency graph for old/sensors/imu_microstrain/clock_test.cpp:

Functions

int frequency_of_primes (int n)
 
int timeval_subtract (struct timeval *result, struct timeval *x, struct timeval *y)
 
float elapsed_time (struct timeval dif, struct timeval a, struct timeval b)
 
int main ()
 

Function Documentation

int frequency_of_primes ( int  n)
35  {
36  int i,j;
37  int freq=n-1;
38  for (i=2; i<=n; ++i) for (j=sqrt(i);j>1;--j) if (i%j==0) {--freq; break;}
39  return freq;
40 }
int i
Definition: rw_test.cpp:37
JHUFF_TBL long freq[]
Definition: jchuff.h:47
int timeval_subtract ( struct timeval *  result,
struct timeval *  x,
struct timeval *  y 
)
43 {
44  /* Perform the carry for the later subtraction by updating y. */
45  if (x->tv_usec < y->tv_usec) {
46  int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
47  y->tv_usec -= 1000000 * nsec;
48  y->tv_sec += nsec;
49  }
50  if (x->tv_usec - y->tv_usec > 1000000) {
51  int nsec = (y->tv_usec - x->tv_usec) / 1000000;
52  y->tv_usec += 1000000 * nsec;
53  y->tv_sec -= nsec;
54  }
55 
56  /* Compute the time remaining to wait.
57  tv_usec is certainly positive. */
58  result->tv_sec = x->tv_sec - y->tv_sec;
59  result->tv_usec = x->tv_usec - y->tv_usec;
60 
61  /* Return 1 if result is negative. */
62  return x->tv_sec < y->tv_sec;
63 }
y
Definition: inputfile.py:6
x
Definition: inputfile.py:6
float elapsed_time ( struct timeval  dif,
struct timeval  a,
struct timeval  b 
)
66 {
67 /*Subtract the timevals*/
68 timeval_subtract(&dif,&a,&b);
69 
70 /* Calculate and return difference in milliseconds */
71 return -dif.tv_sec*1000.0-dif.tv_usec/1000.0;
72 }
long b
Definition: jpegint.h:371
int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y)
Definition: old/sensors/imu_microstrain/clock_test.cpp:42
Definition: eci2kep_test.cpp:33
int main ( )
75 {
76  int f;
77  int ti,tf,dt;
78  printf ("Calculating...\n");
79 
80  struct itimerval *v;
81  struct itimerval *ov=NULL;
82 
83  struct timeval tv1,tv2,diff;
84  struct timezone tz;
85  struct tm *tm;
86 
87  float k;
88 
89  ti = clock();
90  //setitimer(ITIMER_REAL,v, ov);
91  gettimeofday(&tv1, &tz);
92  f = frequency_of_primes (9000);
93  gettimeofday(&tv2, &tz);
94  //getitimer(ITIMER_REAL,v);
95  tf = clock();
96 
97  tm=localtime(&tv1.tv_sec);
98  printf(" %d:%02d:%02d %d \n", tm->tm_hour, tm->tm_min,
99  tm->tm_sec, tv1.tv_usec);
100 
101  tm=localtime(&tv2.tv_sec);
102  printf(" %d:%02d:%02d %d \n", tm->tm_hour, tm->tm_min,
103  tm->tm_sec, tv2.tv_usec);
104 
105  //timeval_subtract(&diff, &tv1, &tv2);
106  k = elapsed_time(diff, tv1, tv2);
107 
108  //printf("It took me %d microseconds...\n", -diff.tv_sec*1000000-diff.tv_usec);
109  printf("It took me %f milliseconds\n", k);
110  //printf("It took me %d microseconds... \n", v.it_value.tv_usec);
111 
112 
113  dt = tf - ti;
114  printf ("The number of primes lower than 100,000 is: %d\n",f);
115  printf ("It took me %d clicks (%f seconds). CPS: %ld\n",dt,dt/(double)CLOCKS_PER_SEC,(double)CLOCKS_PER_SEC);
116 
117  time_t seconds;
118 
119  time_t now = time(0);
120  //time_t time;
121  //time(&time)
122 
123  seconds = time (&now);
124  printf ("%ld hours since January 1, 1970\n", seconds/3600);
125 
126  return 0;
127 }
ElapsedTime dt
Definition: agent_file3.cpp:183
float elapsed_time(struct timeval dif, struct timeval a, struct timeval b)
Definition: old/sensors/imu_microstrain/clock_test.cpp:65
int frequency_of_primes(int n)
Definition: old/sensors/imu_microstrain/clock_test.cpp:35