-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbenchmark.c
More file actions
139 lines (107 loc) · 2.39 KB
/
benchmark.c
File metadata and controls
139 lines (107 loc) · 2.39 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <stdio.h>
#include <sys/time.h>
#include <stdlib.h>
#define K10 1000*10
#define K100 1000*100
#define M1 1000*1000
#define M10 1000*1000*10
#define M100 1000*1000*100
#define M500 1000*1000*500
#define G1 1000*1000*1000
struct timeval t0, t1;
void welcome(){
printf("This simple benchmark tests single core performance of CPU and RAM, created c2h2 v0.1.\n\n");
}
long int clk_start(){
return gettimeofday(&t0, NULL);
}
long int clk_elasped(){
gettimeofday(&t1, NULL);
long int diff = ((t1.tv_usec + 1000000 * t1.tv_sec) - (t0.tv_usec + 1000000 * t0.tv_sec))/1000;
return diff;
}
void publish_result(char* name, long int ms){
static int cnt=0;
printf("BENCHMARK: %d| %s: %ld .\n",cnt++, name, ms);
}
float bench_memcpy(){
int *a,*b,*c,*d;
int i,size;
long int te;
float speed;
size= 1024*256; //256KB
a=(int*)malloc(size);
b=(int*)malloc(size);
c=(int*)malloc(size);
d=(int*)malloc(size);
memset(c, 0xFF, size);
memset(d, 0xAA, size);
clk_start();
for(i=0; i<K10; i++){
memcpy(a, c, size);
memcpy(b, d, size);
memcpy(b, c, size);
memcpy(a, d, size);
}
te=clk_elasped();
speed = (float)i/(float)te*1000.0;
publish_result("memcpy of 256KB data in MB/s ", speed);
}
float bench_int(){
int a,b,c,d,e,f,g,z;
long int te;
int i;
float speed;
a=0; b=10; c=123; d=2313; e=-123; f=233684; g=-1231235,z=123;
clk_start();
for(i=0; i<M100; i++){
a=b+c+d+e+f+g;
c=a*b-c*e-f*g;
d=a/z+b/z+c/z+d/z+e/z+f/z+g/z;
a=z+a+b+c+d+e-f-g;
}
te=clk_elasped();
speed = (float)i/(float)te;
publish_result("int calculation in Kloops/sec", speed);
}
float bench_float(){
float a,b,c,d,z, speed;
long int te;
int i;
a=0.5;
b=1.5;
c=4.5;
d=6.25;
z=4.123;
clk_start();
for(i=0; i<M100; i++){
a=a+b; b=a-c; c=a-b; d=d+d;
a=d*a; b=a/c; c=b*a; d=c/a;
d=a+b-c+d-z+z;
}
te=clk_elasped();
speed = (float)i/(float)te;
publish_result("float calculation in Kloops/sec", speed);
}
float bench_malloc(){
long int te;
int i;
void* dummy;
float speed;
clk_start();
for(i=0; i<M1; i++){
dummy = (void*)malloc(1024*1024);
free(dummy);
}
te=clk_elasped();
speed = (float)i/(float)te;
publish_result("malloc and free in Ktimes/sec ", speed);
}
int main(){
welcome();
bench_malloc();
bench_memcpy();
bench_int();
bench_float();
return 0;
}