| 1 |
#include <iostream> |
| 2 |
#include <fstream> |
| 3 |
#include <cstdlib> |
| 4 |
|
| 5 |
#include "test_utils.hh" |
| 6 |
|
| 7 |
#include "geners/BinaryFileArchive.hh" |
| 8 |
#include "geners/ColumnPacker.hh" |
| 9 |
#include "geners/IOPtr.hh" |
| 10 |
|
| 11 |
using namespace gs; |
| 12 |
using namespace std; |
| 13 |
|
| 14 |
#ifdef CPP11_STD_AVAILABLE |
| 15 |
|
| 16 |
static unsigned MB; |
| 17 |
static const char* filename; |
| 18 |
static const char* objname; |
| 19 |
|
| 20 |
#define MEGABYTE 1048576ULL |
| 21 |
|
| 22 |
#define io_proxy(obj) gs::make_IOProxy( obj , #obj ) |
| 23 |
|
| 24 |
void usage_and_exit(const char* prog) |
| 25 |
{ |
| 26 |
cerr << "\nUsage: " << parse_progname(prog) |
| 27 |
<< " archive object_name size_in_MB\n" << endl; |
| 28 |
exit(1); |
| 29 |
} |
| 30 |
|
| 31 |
void make_big_tuple() |
| 32 |
{ |
| 33 |
BinaryFileArchive ar(filename, "w:z=z", "Huge pack test"); |
| 34 |
if (!ar.isWritable()) |
| 35 |
{ |
| 36 |
std::cerr << "Failed to open archive \"" << ar.name() |
| 37 |
<< "\" for writing" << std::endl; |
| 38 |
return; |
| 39 |
} |
| 40 |
|
| 41 |
double d; |
| 42 |
long double ld; |
| 43 |
long li; |
| 44 |
unsigned long uli; |
| 45 |
long long lli; |
| 46 |
unsigned long long ulli; |
| 47 |
|
| 48 |
auto t = std::make_tuple( |
| 49 |
io_proxy(d), |
| 50 |
io_proxy(ld), |
| 51 |
io_proxy(li), |
| 52 |
io_proxy(uli), |
| 53 |
io_proxy(lli), |
| 54 |
io_proxy(ulli) |
| 55 |
); |
| 56 |
|
| 57 |
unsigned long rowSize = sizeof(d) + sizeof(ld) + sizeof(li) + |
| 58 |
sizeof(uli) + sizeof(lli) + sizeof(ulli); |
| 59 |
unsigned long nrows = MB*MEGABYTE/rowSize; |
| 60 |
|
| 61 |
ColumnPacker<decltype(t)> nt("huge", ar, objname, "my category", t); |
| 62 |
|
| 63 |
for (unsigned long i=0; i<nrows; ++i) |
| 64 |
{ |
| 65 |
unsigned long j = std::tuple_size<decltype(t)>::value*nrows; |
| 66 |
|
| 67 |
d = j++; |
| 68 |
ld = j++; |
| 69 |
li = j++; |
| 70 |
uli = j++; |
| 71 |
lli = j++; |
| 72 |
ulli = j++; |
| 73 |
|
| 74 |
nt.fill(t); |
| 75 |
} |
| 76 |
|
| 77 |
nt.write(); |
| 78 |
ar.flush(); |
| 79 |
cout << "Wrote " << nrows << " rows" << endl; |
| 80 |
} |
| 81 |
|
| 82 |
int main(int argc, char const* argv[]) |
| 83 |
{ |
| 84 |
if (argc != 4) |
| 85 |
usage_and_exit(argv[0]); |
| 86 |
|
| 87 |
filename = argv[1]; |
| 88 |
objname = argv[2]; |
| 89 |
|
| 90 |
if (parse_unsigned(argv[3], &MB)) |
| 91 |
usage_and_exit(argv[0]); |
| 92 |
|
| 93 |
if (MB == 0) |
| 94 |
usage_and_exit(argv[0]); |
| 95 |
|
| 96 |
const double t = time_of_run(make_big_tuple, 1); |
| 97 |
cout << "Program took " << t/1000000 << " sec" << endl; |
| 98 |
|
| 99 |
return 0; |
| 100 |
} |
| 101 |
|
| 102 |
#else // CPP11_STD_AVAILABLE |
| 103 |
|
| 104 |
int main(int argc, char const* argv[]) |
| 105 |
{ |
| 106 |
cout << "Please recompile with C++11 features enabled" << endl; |
| 107 |
return 0; |
| 108 |
} |
| 109 |
|
| 110 |
#endif // CPP11_STD_AVAILABLE |