-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_fixed_len_page.cc
executable file
·85 lines (67 loc) · 2.12 KB
/
read_fixed_len_page.cc
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string.h>
#include <sys/timeb.h>
#include "library.h"
int main(int argc, char** argv) {
if (argc < 3) {
std::cout << "Error, usage must be:\n";
std::cout << "./read_fixed_len_page <page_file> <page_size>\n";
return 1;
}
bool show_output = true;
if (argc == 4 && strcmp(argv[3], "--benchmark-mode") == 0) {
show_output = false;
}
std::ofstream null_out("/dev/null");
int page_size = atoi(argv[2]);
int record_size = 100 * 10;
std::ifstream page_file;
page_file.open(argv[1]);
if (!page_file)
{
std::cout << "Error, could not find file " << argv[1] << "\n";
return 1;
}
Page page;
struct timeb t;
ftime(&t);
long start_time_in_ms = (t.time * 1000) + t.millitm;
char buf[page_size];
while (page_file.read(buf, page_size)) {
// clear the page
init_fixed_len_page(&page, page_size, record_size);
for (int i = 0; i < fixed_len_page_capacity(&page); ++i) {
Record *r = new Record;
fixed_len_read(buf + (i * record_size), record_size, r);
write_fixed_len_page(&page, i, r);
// print entries to /dev/null
for (Record::iterator it = r->begin(); it != r->end(); ++it) {
if (it + 1 == r->end()) {
if (show_output) {
std::cout << *it;
} else {
null_out << *it;
}
} else {
if (show_output) {
std::cout << *it << ",";
} else {
null_out << *it << ",";
}
}
}
if (show_output) {
std::cout << "\n";
} else {
null_out << "\n";
}
}
}
ftime(&t);
long total_run_time = ((t.time * 1000) + t.millitm) - start_time_in_ms;
page_file.close();
std::cout << "TOTAL TIME: " << total_run_time << " milliseconds\n";
return 0;
}