-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils_testsuite.c
More file actions
61 lines (50 loc) · 1.19 KB
/
utils_testsuite.c
File metadata and controls
61 lines (50 loc) · 1.19 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include "miniunit.h"
#include "utils.h"
int _descriptive_statistics() {
mu_start();
//
int num_tests = 100000;
double rand_nums[100000] = {0.0};
double total = 0.0;
for(int i = 0; i < num_tests; i++) {
rand_nums[i] = rand_double();
total += rand_nums[i];
}
double mean = total / num_tests;
total = 0.0;
for(int j = 0; j < num_tests; j++) {
total += pow((rand_nums[j] - mean), 2.0);
}
double variance = total / num_tests;
printf("Mean: %.5f\n", mean);
printf("Variance: %.5f\n", variance);
//
mu_end();
}
int _rand_double_time_1() {
mu_start();
//
double time_2e7, time_1_ns;
clock_t start, end;
int num_rands = 20000000;
int s_to_ns = 1000000000;
start = clock();
for(long i = 0; i < num_rands; i++) {
rand_double();
}
end = clock();
time_2e7 = (((double)(end - start)) / CLOCKS_PER_SEC);
time_1_ns = (time_2e7 / num_rands) * s_to_ns;
printf("Time(2E7): %3.5f s\n", time_2e7);
printf("Time(1): %2.5f ns\n", time_1_ns);
//
mu_end();
}
int utils_tests() {
mu_run(_descriptive_statistics);
mu_run(_rand_double_time_1);
return EXIT_SUCCESS;
}