8 #include <boost/iterator/iterator_facade.hpp>
9 #include <boost/filesystem/operations.hpp>
10 #include <boost/filesystem/directory.hpp>
37 std::string show_size(
unsigned int sz) {
38 std::ostringstream oss;
40 oss << sz / 1000000 <<
"M";
41 }
else if (sz > 1000) {
42 oss << sz / 1000 <<
"k";
50 std::chrono::steady_clock::time_point start_time_;
53 start_time_ = std::chrono::steady_clock::now();
56 double elapsed()
const {
57 auto end_time = std::chrono::steady_clock::now();
58 auto time_span = std::chrono::duration_cast<
59 std::chrono::duration<double> >(end_time - start_time_);
60 return time_span.count();
64 void benchmark_size(std::string path, std::string type) {
65 unsigned int size = 0;
66 if (boost::filesystem::is_directory(path)) {
67 for (boost::filesystem::directory_iterator it(path);
68 it != boost::filesystem::directory_iterator(); it++) {
69 size += boost::filesystem::file_size(*it);
72 size = boost::filesystem::file_size(path);
74 std::cout << type <<
", size, " << show_size(size) <<
", " << size
80 std::size_t total_size = 0;
81 for (
unsigned int i = 0; i < 2 * scale; ++i) {
83 pf.
get(child).set_static_mass(1);
84 pf.
get(child).set_static_radius(1.0 + i / 18.77);
85 af.
get(child).set_static_element(7);
86 total_size +=
sizeof(int) * 1 +
sizeof(
float) * 2;
93 std::size_t total_size = 0;
94 for (
unsigned int i = 0; i < 60 * scale; ++i) {
95 std::ostringstream oss;
98 rf.
get(child).set_static_residue_type(
"cys");
99 rf.
get(child).set_static_residue_index(i);
100 total_size +=
sizeof(int) + 4;
101 total_size += create_residue(child, af, pf);
111 std::size_t total_size = 0;
112 for (
unsigned int i = 0; i < 3 * scale; ++i) {
113 std::ostringstream oss;
116 cf.get(child).set_static_chain_id(oss.str());
117 total_size += oss.str().size();
118 total_size += create_chain(child, rf, af, pf);
128 std::size_t total_size = 0;
131 (n.get_index() + 1 + frame) / 19.0,
132 (n.get_index() + 2 + frame) / 23.0);
137 total_size +=
sizeof(float) * 3;
139 return std::make_pair(ret[0] + ret[1] + ret[2], total_size);
143 std::size_t hierarchy_size = create_hierarchy(file);
145 if (file.
get_node(n).get_children().empty()) {
149 return boost::make_tuple(hierarchy_size);
155 double check_value = 0;
156 std::size_t frame_size = 0;
157 for (
unsigned int i = 0; i < 20; ++i) {
159 std::pair<double, std::size_t> cur = create_frame(file, ipf, atoms, i);
160 check_value += cur.first;
161 frame_size += cur.second;
163 return boost::make_tuple(check_value, frame_size);
173 if (ipcf.get_is(cur)) {
174 ret += ipcf.get(cur).get_radius();
177 queue.insert(queue.end(), children.begin(), children.end());
178 }
while (!queue.empty());
186 file.set_current_frame(fr);
188 RMF::Vector3 cur = ipcf.get(file.get_node(n)).get_coordinates();
194 return v[0] + v[1] + v[2];
197 std::pair<std::size_t, std::size_t> benchmark_create(
RMF::FileHandle file,
201 boost::tuple<std::size_t> cur = create(file, atoms);
202 std::cout << type <<
", create, " << timer.elapsed() <<
", " << cur.get<0>()
205 boost::tuple<double, std::size_t> frames = create_frames(file, atoms);
206 std::cout << type <<
", create frame, " << frame_timer.elapsed() / 20.0
207 <<
", " << frames.get<0>() << std::endl;
208 return std::make_pair(cur.get<0>(), frames.get<1>());
216 while (timer.elapsed() < 1) {
220 std::cout << type <<
", traverse, " << timer.elapsed() / count <<
", " << t
228 if (ipcf.get_is(file.get_node(n))) nodes.push_back(n);
231 double dist = load(file, nodes);
232 std::cout << type <<
", load, " << timer.elapsed() / 20.0 <<
", " << dist
240 while (timer.elapsed() < 1) {
245 std::cout << type <<
", open, " << timer.elapsed() / count <<
", 0"
251 int main(
int,
char**) {
254 std::string name_base = RMF::internal::get_unique_path();
256 std::cout << name_base << std::endl;
259 const std::string name = name_base +
".rmf";
262 std::pair<std::size_t, std::size_t> sizes = benchmark_create(fh,
"rmf");
263 std::cout <<
"raw, total, " << show_size(sizes.first + sizes.second)
264 <<
", " << (sizes.first + sizes.second) << std::endl;
265 std::cout <<
"raw, frame, " << show_size(sizes.second) <<
", "
266 << sizes.second << std::endl;
270 benchmark_traverse(fh,
"rmf");
271 benchmark_load(fh,
"rmf");
273 benchmark_size(name,
"rmf");
276 const std::string name = name_base +
".rmfz";
279 benchmark_create(fh,
"rmfz");
283 benchmark_traverse(fh,
"rmfz");
284 benchmark_load(fh,
"rmfz");
286 benchmark_size(name,
"rmfz");
288 #if RMF_HAS_DEPRECATED_BACKENDS
290 const std::string name = name_base +
".rmf-hdf5";
293 benchmark_create(fh,
"hdf5");
297 benchmark_traverse(fh,
"hdf5");
298 benchmark_load(fh,
"hdf5");
300 benchmark_size(name,
"hdf5");
307 benchmark_create(fh,
"buffer");
312 std::cout <<
"buffer"
313 <<
", open, " << timer.elapsed() <<
", 0" << std::endl;
314 benchmark_traverse(fh,
"buffer");
315 benchmark_load(fh,
"buffer");
319 catch (
const std::exception& e) {
320 std::cerr <<
"Exception thrown: " << e.what() << std::endl;
NodeHandle add_child(std::string name, NodeType t) const
ParticleConst get(NodeConstHandle nh) const
FileConstHandle open_rmf_buffer_read_only(BufferConstHandle buffer)
const NodeType REPRESENTATION
Represent part of a molecule.
Helper functions for manipulating RMF files.
A handle for a particular node in the hierarchy.
ResidueConst get(NodeConstHandle nh) const
FileHandle create_rmf_buffer(BufferHandle buffer)
Create an RMF in a buffer.
FrameID add_frame(std::string name, FrameType t=FRAME) const
Add a frame and make it the current frame.
A handle for a particular node in a read-only hierarchy.
void set_log_level(std::string level)
const FrameType FRAME
A frame in a sequence of frames.
A handle for a read-only RMF file.
FileConstHandle open_rmf_file_read_only(std::string path)
FileHandle create_rmf_file(std::string path)
Create an RMF from a file system path.
A handle for an RMF file.
Declaration for RMF::FileHandle.
Declaration of NodeConstHandle.
Declaration of NodeHandle.
The various enums used in RMF.
Manage a shared buffer for storing a RMF.
std::vector< NodeConstHandle > NodeConstHandles
Pass a list of them.
NodeConstHandle get_root_node() const
Return the root of the hierarchy.
Helper functions for manipulating RMF files.
void close()
Explicitly close the file handle.
Handle read/write of Model data from/to files.
Functions and macros for logging.
Various general useful macros for IMP.
NodeHandle get_node(NodeID id) const
Return a NodeHandle from a NodeID.
std::vector< NodeID > NodeIDs
AtomConst get(NodeConstHandle nh) const
Declare RMF::BufferHandle.
NodeHandle get_root_node() const
Return the root of the hierarchy stored in the file.