Update unit tests.
[matches/MCTX3420.git] / testing / data_performance / main.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <assert.h>
4 #include <sys/time.h>
5
6 typedef struct
7 {
8         float time;
9         float value;
10 } DataPoint;
11
12
13
14
15 int main(int argc, char ** argv)
16 {
17         assert(argc == 3);
18         
19         int bufsiz = atoi(argv[1]);
20         int numpoints = atoi(argv[2]);
21         assert(bufsiz > 0);
22         DataPoint * buffer = (DataPoint*)(calloc(bufsiz, sizeof(DataPoint)));
23
24         struct timeval start_time;
25         gettimeofday(&start_time, NULL);
26
27         FILE * file = fopen("data.bin", "wb");
28         
29         int i = 0;
30         while (i < numpoints)
31         {
32                 int j = 0;
33                 for (j = 0; j < bufsiz && i < numpoints; ++j)
34                 {
35                         buffer[j].time = i;
36                         buffer[j].value = i;
37                         
38                 }
39                 i += j;
40                 assert(fwrite(buffer, sizeof(DataPoint), j, file) == j);
41                 
42
43         }
44
45         fclose(file);
46         
47
48         struct timeval end_time;
49         gettimeofday(&end_time, NULL);
50
51         free(buffer);
52         float time_elapsed = (float)(end_time.tv_sec - start_time.tv_sec) + 1e-6*(end_time.tv_usec - start_time.tv_usec);
53         printf("%f\n", time_elapsed);
54         return 0;
55 }

UCC git Repository :: git.ucc.asn.au