limit fstBC to 30bp in Python3 ver.
[GalaxyCodeBases.git] / c_cpp / lib / klib / test / kvec_test.cc
blob1015574e4bedc71c457b41764617e7c576cd94fa
1 #include <vector>
2 #include <time.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include "kvec.h"
7 int main()
9 int M = 10, N = 20000000, i, j;
10 clock_t t;
11 t = clock();
12 for (i = 0; i < M; ++i) {
13 int *array = (int*)malloc(N * sizeof(int));
14 for (j = 0; j < N; ++j) array[j] = j;
15 free(array);
17 printf("C array, preallocated: %.3f sec\n",
18 (float)(clock() - t) / CLOCKS_PER_SEC);
19 t = clock();
20 for (i = 0; i < M; ++i) {
21 int *array = 0, max = 0;
22 for (j = 0; j < N; ++j) {
23 if (j == max) {
24 max = !max? 1 : max << 1;
25 array = (int*)realloc(array, sizeof(int)*max);
27 array[j] = j;
29 free(array);
31 printf("C array, dynamic: %.3f sec\n",
32 (float)(clock() - t) / CLOCKS_PER_SEC);
33 t = clock();
34 for (i = 0; i < M; ++i) {
35 kvec_t(int) array;
36 kv_init(array);
37 kv_resize(int, array, N);
38 for (j = 0; j < N; ++j) kv_a(int, array, j) = j;
39 kv_destroy(array);
41 printf("C vector, dynamic(kv_a): %.3f sec\n",
42 (float)(clock() - t) / CLOCKS_PER_SEC);
43 t = clock();
44 for (i = 0; i < M; ++i) {
45 kvec_t(int) array;
46 kv_init(array);
47 for (j = 0; j < N; ++j)
48 kv_push(int, array, j);
49 kv_destroy(array);
51 printf("C vector, dynamic(kv_push): %.3f sec\n",
52 (float)(clock() - t) / CLOCKS_PER_SEC);
53 t = clock();
54 for (i = 0; i < M; ++i) {
55 std::vector<int> array;
56 array.reserve(N);
57 for (j = 0; j < N; ++j) array[j] = j;
59 printf("C++ vector, preallocated: %.3f sec\n",
60 (float)(clock() - t) / CLOCKS_PER_SEC);
61 t = clock();
62 for (i = 0; i < M; ++i) {
63 std::vector<int> array;
64 for (j = 0; j < N; ++j) array.push_back(j);
66 printf("C++ vector, dynamic: %.3f sec\n",
67 (float)(clock() - t) / CLOCKS_PER_SEC);
68 return 0;