chunkedseq
container library for large in-memory data sets
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
do_fifo.cpp
Go to the documentation of this file.
1 
2 #define BOOTNEW 1
3 
4 #include <assert.h>
5 
6 #include "cmdline.hpp"
7 #include "atomic.hpp"
8 #include "microtime.hpp"
9 
10 #include "container.hpp"
11 #include "fixedcapacity.hpp"
12 #include "chunkedseq.hpp"
13 #include "cachedmeasure.hpp"
14 
15 
16 using namespace pasl;
17 using namespace pasl::util;
19 
20 /***********************************************************************/
21 
22 typedef size_t result_t;
23 
24 
26 double exec_time;
27 
28 /*---------------------------------------------------------------------*/
29 
30 class bytes_8 {
31 public:
32  uint64_t data;
33  bytes_8() { }
34  bytes_8(char c) {
35  data = (uint64_t)c;
36  }
37  bytes_8(size_t i) {
38  data = i;
39  }
40  size_t get() const {
41  return data;
42  }
43  char get_char() const {
44  return (char) (data % 256);
45  }
46  bool operator==(const bytes_8 other) {
47  return data == other.data;
48  }
49 };
50 
51 
52 /*---------------------------------------------------------------------*/
53 /* Scenarios */
54 
55 
56 // #define FIFO_LIFO_ONLY_COUNT_POP 1
57 
58 template <class Datastruct>
59 void scenario_lifo() {
60  typedef typename Datastruct::value_type value_type;
61  size_t nb_total = (size_t) cmdline::parse_or_default_int64("n", 100000000);
62  size_t repeat = (size_t) cmdline::parse_or_default_int64("r", 1000);
63  size_t block = nb_total / repeat;
64  printf("length %lld\n",block);
65  uint64_t start_time = microtime::now();
66  Datastruct d;
67  res = 0;
68  for (size_t j = 0; j < repeat; j++) {
69  for (size_t i = 0; i < block; i++) {
70  d.push_back(value_type(i));
71  res += i;
72  }
73  for (size_t i = 0; i < block; i++) {
74  res += d.pop_back().get();
75  }
76  }
77  exec_time = microtime::seconds_since(start_time);
78 }
79 
80 template <class Datastruct>
81 void scenario_fifo() {
82  typedef typename Datastruct::value_type value_type;
83  size_t nb_total = (size_t) cmdline::parse_or_default_int64("n", 100000000);
84  size_t repeat = (size_t) cmdline::parse_or_default_int64("r", 1000);
85  size_t block = nb_total / repeat;
86  printf("length %lld\n",block);
87  uint64_t start_time = microtime::now();
88  Datastruct d;
89  res = 0;
90  for (size_t j = 0; j < repeat; j++) {
91  for (size_t i = 0; i < block; i++) {
92  d.push_back(value_type(i));
93  res += i;
94  }
95  for (size_t i = 0; i < block; i++) {
96  res += d.pop_front().get();
97  }
98  }
99  exec_time = microtime::seconds_since(start_time);
100 }
101 
102 
103 
104 /*---------------------------------------------------------------------*/
105 // dispatch sequences
106 
107 using Item = bytes_8;
108 
109 
110 using seq1_type = pasl::data::stl::deque_seq<Item>;
111 
113  Item,
114  512,
117 
119  Item,
120  512,
123 
124 #if 0
125 
126 using seq3_type = chunkedseq::bootstrapped::deque<
127  Item,
128  512,
131 #endif
132 
133 
134 int main(int argc, char** argv) {
135  pasl::util::cmdline::set(argc, argv);
136  res = 0;
137 
138  std::string sequence = cmdline::parse_or_default_string("sequence", "stl_deque");
139  std::string scenario = cmdline::parse_or_default_string("scenario", "fifo");
140  int chunk_size = cmdline::parse_or_default_int("chunk_size", 512);
141  if (chunk_size != 512) {
142  printf("not valid chunk size\n");
143  exit(1);
144  }
145 
146  if (scenario == "fifo") {
147  if (sequence == "stl_deque") {
148  scenario_fifo<seq1_type>();
149  } else
150  if (sequence == "chunkedseq") { // ptr
151  scenario_fifo<seq2_type>();
152 #if 0
153  } else if (sequence == "chunkedseq_ptrx") {
154  scenario_fifo<seq3_type>();
155 #endif
156  } else if (sequence == "chunkedftree") {
157  scenario_fifo<fftree_deque_type>();
158  } else {
159  printf("not valid sequence\n");
160  exit(1);
161  }
162  }
163  else if (scenario == "lifo") {
164  if (sequence == "stl_deque") {
165  scenario_lifo<seq1_type>();
166  } else
167  if (sequence == "chunkedseq") {
168  scenario_lifo<seq2_type>();
169  #if 0
170  } else if (sequence == "chunkedseq_ptrx") {
171  scenario_fifo<seq3_type>();
172  #endif
173  } else if (sequence == "chunkedftree") {
174  scenario_fifo<fftree_deque_type>();
175  } else {
176  printf("not valid sequence\n");
177  exit(1);
178  }
179  }
180 
181  printf ("exectime %lf\n", exec_time);
182  printf("result %lld\n", (long long)res);
183 
184  return 0;
185 }
186 
187 
188 
189 
190 /***********************************************************************/
pasl::data::stl::deque_seq< Item > seq1_type
Definition: do_fifo.cpp:110
double exec_time
Definition: do_fifo.cpp:26
chunkedseqbase< basic_deque_configuration< Item, Chunk_capacity, Cache, Chunk_struct, bootchunkedseq::cdeque, Item_alloc >> deque
Definition: chunkedseq.hpp:228
void scenario_lifo()
Definition: do_fifo.cpp:59
Definition: algebra.hpp:18
Fixed capacity vectors.
Definitions of a few cached-measurement policies.
size_t result_t
Definition: do_fifo.cpp:22
chunkedseq::bootstrapped::deque< Item, 512, pasl::data::cachedmeasure::trivial< Item, size_t >, data::fixedcapacity::heap_allocated::ringbuffer_ptr > seq2_type
Definition: do_fifo.cpp:116
chunkedseq::ftree::deque< Item, 512, pasl::data::cachedmeasure::trivial< Item, size_t >, data::fixedcapacity::heap_allocated::ringbuffer_ptr > fftree_deque_type
Definition: do_fifo.cpp:122
int main(int argc, char **argv)
Definition: do_fifo.cpp:134
size_t result_t
Definition: bench.cpp:41
result_t res
Definition: do_fifo.cpp:25
bytes_8 Item
Definition: do_fifo.cpp:107
void scenario_fifo()
Definition: do_fifo.cpp:81
Chunked-sequence functor.