containers.cpp
Go to the documentation of this file.
1 
9 /*****************************************************************************
10 ** Includes
11 *****************************************************************************/
12 
13 #include <algorithm>
14 #include <iostream>
15 #include <vector>
16 #include <ecl/containers/array.hpp>
17 #include <ecl/threads/priority.hpp>
18 #include <ecl/time/stopwatch.hpp>
19 #include <ecl/time/timestamp.hpp>
20 
21 /*****************************************************************************
22 ** Using
23 *****************************************************************************/
24 
25 using std::string;
26 using std::vector;
27 using ecl::Array;
30 using ecl::StopWatch;
31 using ecl::TimeStamp;
32 
33 /*****************************************************************************
34 ** Main
35 *****************************************************************************/
36 
37 
38 int main()
39 {
40  try {
41  ecl::set_priority(RealTimePriority4);
42  } catch ( StandardException &e ) {
43  // dont worry about it.
44  }
45  StopWatch stopwatch;
46  TimeStamp timestamp[5];
47 
48  Array<int,4> array_tmp;
49  array_tmp << 3,4,6,3;
50  array_tmp << 3,4,6,3;
51  array_tmp << 3,4,6,3;
52 
53  std::cout << std::endl;
54  std::cout << "***********************************************************" << std::endl;
55  std::cout << " Constructors" << std::endl;
56  std::cout << "***********************************************************" << std::endl;
57  std::cout << std::endl;
58 
59  stopwatch.restart();
60  // Array [manual]
61  Array<int,4> array1;
62  for ( int i = 0; i < 4; ++i ) {
63  array1[i] = 3;
64  }
65  timestamp[0] = stopwatch.split();
66 
67  // Array [comma]
68  Array<int,4> array2;
69  array2 << 3,3,3,3;
70  timestamp[1] = stopwatch.split();
71 
72  // Array [blueprint]
74  timestamp[2] = stopwatch.split();
75 
76  // Vector [manual]
77  vector<int> v1(4);
78  for ( int i = 0; i < 4; ++i ) {
79  v1[i] = 3;
80  }
81  timestamp[3] = stopwatch.split();
82 
83  // Vector [manual]
84  int a1[4];
85  for ( int i = 0; i < 4; ++i ) {
86  a1[i] = 3;
87  }
88  timestamp[4] = stopwatch.split();
89 
90  std::cout << "carray [manual] : " << timestamp[4] << std::endl;
91  std::cout << "Array [blueprint]: " << timestamp[2] << std::endl;
92  std::cout << "Array [manual] : " << timestamp[0] << std::endl;
93  std::cout << "Array [comma] : " << timestamp[1] << std::endl;
94  std::cout << "Vector [manual] : " << timestamp[3] << std::endl;
95 
96  std::cout << std::endl;
97  std::cout << "***********************************************************" << std::endl;
98  std::cout << " Accessors" << std::endl;
99  std::cout << "***********************************************************" << std::endl;
100  std::cout << std::endl;
101 
102  int elements[4];
103 
104  stopwatch.restart();
105  for (int i = 0; i < 4; ++i ) { elements[i] = array1[i]; }
106  timestamp[0] = stopwatch.split();
107 
108  for (int i = 0; i < 4; ++i ) { elements[i] = array1.at(i); }
109  timestamp[1] = stopwatch.split();
110 
111  for (int i = 0; i < 4; ++i ) { elements[i] = v1[i]; }
112  timestamp[2] = stopwatch.split();
113 
114  for (int i = 0; i < 4; ++i ) { elements[i] = v1.at(i); }
115  timestamp[3] = stopwatch.split();
116 
117  for (int i = 0; i < 4; ++i ) { elements[i] = a1[i]; }
118  timestamp[4] = stopwatch.split();
119 
120  std::cout << "carray [] : " << timestamp[4] << std::endl;
121  std::cout << "Array [] : " << timestamp[0] << std::endl;
122  std::cout << "Array at : " << timestamp[1] << std::endl;
123  std::cout << "Vector [] : " << timestamp[2] << std::endl;
124  std::cout << "Vector at : " << timestamp[3] << std::endl;
125 
126  std::cout << std::endl;
127  std::cout << "***********************************************************" << std::endl;
128  std::cout << " Setters" << std::endl;
129  std::cout << "***********************************************************" << std::endl;
130  std::cout << std::endl;
131 
132  stopwatch.restart();
133  for (int i = 0; i < 4; ++i ) { array1[i] = 3; }
134  timestamp[0] = stopwatch.split();
135 
136  for (int i = 0; i < 4; ++i ) { array1 = Array<int,4>::Constant(3); }
137  timestamp[1] = stopwatch.split();
138 
139  for (int i = 0; i < 4; ++i ) { v1[i] = 3; }
140  timestamp[2] = stopwatch.split();
141 
142  for (int i = 0; i < 4; ++i ) { a1[i] = 3; }
143  timestamp[3] = stopwatch.split();
144 
145  std::cout << "carray [manual] : " << timestamp[3] << std::endl;
146  std::cout << "Array [blueprint]: " << timestamp[1] << std::endl;
147  std::cout << "Array [manual] : " << timestamp[0] << std::endl;
148  std::cout << "Vector [manual] : " << timestamp[2] << std::endl;
149 
150 return 0;
151 }
152 
int main()
Definition: containers.cpp:38
reference at(size_type i)
RealTimePriority4


ecl_core_apps
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:55