-
Notifications
You must be signed in to change notification settings - Fork 3
/
app7-libc.C
67 lines (52 loc) · 1.17 KB
/
app7-libc.C
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
// test some libc functions (gettimeofday, getpid, memset, memcpy, strncpy)
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include <vector>
using namespace std;
int64_t numIterations = 0;
int Func2 ()
{
// sleep(1);
// printf("sleep finished\n");
// return 1;
static char buffer1[100];
static char buffer2[100];
memset(buffer1, 'a', 100);
strncpy(buffer2, buffer1, 100);
memcpy(buffer2, buffer1, 100);
struct timeval tv;
gettimeofday(&tv, NULL);
return getpid();
}
int Calc1 ()
{
static int result = 0;
for (int i = 0; i < 1000; i++)
{
for (int j = 0; j < 5; j++)
{
result += Func2();
}
numIterations++;
}
return result;
}
int main (int argc, char* argv[])
{
int64_t maxIterations = int64_t(100) * 1000 * 1000;
if (argc > 1)
{
maxIterations = int64_t( atoi(argv[1]) );
}
printf("started, for %lld iterations; PID: %d\n", maxIterations, getpid());
int value = 0;
for (int64_t i = 0; i < maxIterations; i++)
{
value += Calc1();
}
return value;
}