8 #include <boost/iterator/iterator_facade.hpp>
9 #include <boost/version.hpp>
10 #include <boost/filesystem/operations.hpp>
11 #if BOOST_VERSION >= 107200
12 #include <boost/filesystem/directory.hpp>
40 std::string show_size(
unsigned int sz) {
41 std::ostringstream oss;
43 oss << sz / 1000000 <<
"M";
44 }
else if (sz > 1000) {
45 oss << sz / 1000 <<
"k";
53 std::chrono::steady_clock::time_point start_time_;
56 start_time_ = std::chrono::steady_clock::now();
59 double elapsed()
const {
60 auto end_time = std::chrono::steady_clock::now();
61 auto time_span = std::chrono::duration_cast<
62 std::chrono::duration<double> >(end_time - start_time_);
63 return time_span.count();
67 void benchmark_size(std::string path, std::string type) {
68 unsigned int size = 0;
69 if (boost::filesystem::is_directory(path)) {
70 for (boost::filesystem::directory_iterator it(path);
71 it != boost::filesystem::directory_iterator(); it++) {
72 size += boost::filesystem::file_size(*it);
75 size = boost::filesystem::file_size(path);
77 std::cout << type <<
", size, " << show_size(size) <<
", " << size
83 std::size_t total_size = 0;
84 for (
unsigned int i = 0; i < 2 * scale; ++i) {
86 pf.
get(child).set_static_mass(1);
87 pf.
get(child).set_static_radius(1.0 + i / 18.77);
88 af.
get(child).set_static_element(7);
89 total_size +=
sizeof(int) * 1 +
sizeof(
float) * 2;
96 std::size_t total_size = 0;
97 for (
unsigned int i = 0; i < 60 * scale; ++i) {
98 std::ostringstream oss;
101 rf.
get(child).set_static_residue_type(
"cys");
102 rf.
get(child).set_static_residue_index(i);
103 total_size +=
sizeof(int) + 4;
104 total_size += create_residue(child, af, pf);
114 std::size_t total_size = 0;
115 for (
unsigned int i = 0; i < 3 * scale; ++i) {
116 std::ostringstream oss;
119 cf.get(child).set_static_chain_id(oss.str());
120 total_size += oss.str().size();
121 total_size += create_chain(child, rf, af, pf);
131 std::size_t total_size = 0;
134 (n.get_index() + 1 + frame) / 19.0,
135 (n.get_index() + 2 + frame) / 23.0);
140 total_size +=
sizeof(float) * 3;
142 return std::make_pair(ret[0] + ret[1] + ret[2], total_size);
146 std::size_t hierarchy_size = create_hierarchy(file);
148 if (file.
get_node(n).get_children().empty()) {
152 return boost::make_tuple(hierarchy_size);
158 double check_value = 0;
159 std::size_t frame_size = 0;
160 for (
unsigned int i = 0; i < 20; ++i) {
162 std::pair<double, std::size_t> cur = create_frame(file, ipf, atoms, i);
163 check_value += cur.first;
164 frame_size += cur.second;
166 return boost::make_tuple(check_value, frame_size);
176 if (ipcf.get_is(cur)) {
177 ret += ipcf.get(cur).get_radius();
180 queue.insert(queue.end(), children.begin(), children.end());
181 }
while (!queue.empty());
189 file.set_current_frame(fr);
191 RMF::Vector3 cur = ipcf.get(file.get_node(n)).get_coordinates();
197 return v[0] + v[1] + v[2];
200 std::pair<std::size_t, std::size_t> benchmark_create(
RMF::FileHandle file,
204 boost::tuple<std::size_t> cur = create(file, atoms);
205 std::cout << type <<
", create, " << timer.elapsed() <<
", " << cur.get<0>()
208 boost::tuple<double, std::size_t> frames = create_frames(file, atoms);
209 std::cout << type <<
", create frame, " << frame_timer.elapsed() / 20.0
210 <<
", " << frames.get<0>() << std::endl;
211 return std::make_pair(cur.get<0>(), frames.get<1>());
219 while (timer.elapsed() < 1) {
223 std::cout << type <<
", traverse, " << timer.elapsed() / count <<
", " << t
231 if (ipcf.get_is(file.get_node(n))) nodes.push_back(n);
234 double dist = load(file, nodes);
235 std::cout << type <<
", load, " << timer.elapsed() / 20.0 <<
", " << dist
243 while (timer.elapsed() < 1) {
248 std::cout << type <<
", open, " << timer.elapsed() / count <<
", 0"
254 int main(
int,
char**) {
257 std::string name_base = RMF::internal::get_unique_path();
259 std::cout << name_base << std::endl;
262 const std::string name = name_base +
".rmf";
265 std::pair<std::size_t, std::size_t> sizes = benchmark_create(fh,
"rmf");
266 std::cout <<
"raw, total, " << show_size(sizes.first + sizes.second)
267 <<
", " << (sizes.first + sizes.second) << std::endl;
268 std::cout <<
"raw, frame, " << show_size(sizes.second) <<
", "
269 << sizes.second << std::endl;
273 benchmark_traverse(fh,
"rmf");
274 benchmark_load(fh,
"rmf");
276 benchmark_size(name,
"rmf");
279 const std::string name = name_base +
".rmfz";
282 benchmark_create(fh,
"rmfz");
286 benchmark_traverse(fh,
"rmfz");
287 benchmark_load(fh,
"rmfz");
289 benchmark_size(name,
"rmfz");
291 #if RMF_HAS_DEPRECATED_BACKENDS
293 const std::string name = name_base +
".rmf-hdf5";
296 benchmark_create(fh,
"hdf5");
300 benchmark_traverse(fh,
"hdf5");
301 benchmark_load(fh,
"hdf5");
303 benchmark_size(name,
"hdf5");
310 benchmark_create(fh,
"buffer");
315 std::cout <<
"buffer"
316 <<
", open, " << timer.elapsed() <<
", 0" << std::endl;
317 benchmark_traverse(fh,
"buffer");
318 benchmark_load(fh,
"buffer");
322 catch (
const std::exception& e) {
323 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.