forked from ScottOaks/JavaPerformanceTuning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
29 lines (25 loc) · 726 Bytes
/
main.c
File metadata and controls
29 lines (25 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
* Copyright (c) 2013,2014 Scott Oaks. All rights reserved.
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
double calcInC(int);
int main(int argc, char** argv) {
struct timeval then;
gettimeofday(&then, NULL);
int nTrials, nValues;
sscanf(argv[1], "%d", &nTrials);
sscanf(argv[2], "%d", &nValues);
double error = 0;
int i;
srand(time(NULL));
for (i = 0; i < nTrials; i++) {
double average = calcInC(nValues);
error += 50 - average;
}
struct timeval now;
gettimeofday(&now, NULL);
printf("Error: %lf calculated in %ld\n", error, (now.tv_sec - then.tv_sec) * 1000 + now.tv_usec / 1000 - then.tv_usec / 1000);
exit(EXIT_SUCCESS);
}