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