forked from fredrikwidlund/libdynamic_benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector_grow_cpp.cpp
More file actions
44 lines (38 loc) · 913 Bytes
/
vector_grow_cpp.cpp
File metadata and controls
44 lines (38 loc) · 913 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/time.h>
#include <vector>
#include <err.h>
uint64_t ntime()
{
struct timeval tv;
(void) gettimeofday(&tv, NULL);
return ((uint64_t) tv.tv_sec * 1000000000) + ((uint64_t) tv.tv_usec * 1000);
}
int main(int argc, char **argv)
{
uint64_t i, j, t, m[101], n = strtol(argv[1], NULL, 0);
std::vector<uint64_t> v;
t = ntime();
m[0] = 0;
try
{
for (i = 0; i < n; i += n / 100)
{
for (j = 0; j < n / 100; j ++)
{
v.push_back(j);
}
m[i / (n / 100) + 1] = ntime() - t;
}
}
catch(const std::bad_alloc&)
{
err(1, "std::vector::push_back %ld", i);
}
(void) fprintf(stdout, "\"size\",\"time\"\n");
for (i = 0; i <= 100; i ++)
(void) fprintf(stdout, "%ld,%f\n", i * (n / 100), (float) m[i] / 1000000000);
exit(0);
}