8 #include <boost/iterator/iterator_facade.hpp>
9 #include <boost/filesystem/operations.hpp>
36 std::string show_size(
unsigned int sz) {
37 std::ostringstream oss;
39 oss << sz / 1000000 <<
"M";
40 }
else if (sz > 1000) {
41 oss << sz / 1000 <<
"k";
49 std::chrono::steady_clock::time_point start_time_;
52 start_time_ = std::chrono::steady_clock::now();
55 double elapsed()
const {
56 auto end_time = std::chrono::steady_clock::now();
57 auto time_span = std::chrono::duration_cast<
58 std::chrono::duration<double> >(end_time - start_time_);
59 return time_span.count();
63 void benchmark_size(std::string path, std::string type) {
64 unsigned int size = 0;
65 if (boost::filesystem::is_directory(path)) {
66 for (boost::filesystem::directory_iterator it(path);
67 it != boost::filesystem::directory_iterator(); it++) {
68 size += boost::filesystem::file_size(*it);
71 size = boost::filesystem::file_size(path);
73 std::cout << type <<
", size, " << show_size(size) <<
", " << size
79 std::size_t total_size = 0;
80 for (
unsigned int i = 0; i < 2 * scale; ++i) {
82 pf.
get(child).set_static_mass(1);
83 pf.
get(child).set_static_radius(1.0 + i / 18.77);
84 af.
get(child).set_static_element(7);
85 total_size +=
sizeof(int) * 1 +
sizeof(
float) * 2;
92 std::size_t total_size = 0;
93 for (
unsigned int i = 0; i < 60 * scale; ++i) {
94 std::ostringstream oss;
97 rf.
get(child).set_static_residue_type(
"cys");
98 rf.
get(child).set_static_residue_index(i);
99 total_size +=
sizeof(int) + 4;
100 total_size += create_residue(child, af, pf);
110 std::size_t total_size = 0;
111 for (
unsigned int i = 0; i < 3 * scale; ++i) {
112 std::ostringstream oss;
115 cf.get(child).set_static_chain_id(oss.str());
116 total_size += oss.str().size();
117 total_size += create_chain(child, rf, af, pf);
127 std::size_t total_size = 0;
130 (n.get_index() + 1 + frame) / 19.0,
131 (n.get_index() + 2 + frame) / 23.0);
136 total_size +=
sizeof(float) * 3;
138 return std::make_pair(ret[0] + ret[1] + ret[2], total_size);
142 std::size_t hierarchy_size = create_hierarchy(file);
144 if (file.
get_node(n).get_children().empty()) {
148 return boost::make_tuple(hierarchy_size);
154 double check_value = 0;
155 std::size_t frame_size = 0;
156 for (
unsigned int i = 0; i < 20; ++i) {
158 std::pair<double, std::size_t> cur = create_frame(file, ipf, atoms, i);
159 check_value += cur.first;
160 frame_size += cur.second;
162 return boost::make_tuple(check_value, frame_size);
172 if (ipcf.get_is(cur)) {
173 ret += ipcf.get(cur).get_radius();
176 queue.insert(queue.end(), children.begin(), children.end());
177 }
while (!queue.empty());
185 file.set_current_frame(fr);
187 RMF::Vector3 cur = ipcf.get(file.get_node(n)).get_coordinates();
193 return v[0] + v[1] + v[2];
196 std::pair<std::size_t, std::size_t> benchmark_create(
RMF::FileHandle file,
200 boost::tuple<std::size_t> cur = create(file, atoms);
201 std::cout << type <<
", create, " << timer.elapsed() <<
", " << cur.get<0>()
204 boost::tuple<double, std::size_t> frames = create_frames(file, atoms);
205 std::cout << type <<
", create frame, " << frame_timer.elapsed() / 20.0
206 <<
", " << frames.get<0>() << std::endl;
207 return std::make_pair(cur.get<0>(), frames.get<1>());
215 while (timer.elapsed() < 1) {
219 std::cout << type <<
", traverse, " << timer.elapsed() / count <<
", " << t
227 if (ipcf.get_is(file.get_node(n))) nodes.push_back(n);
230 double dist = load(file, nodes);
231 std::cout << type <<
", load, " << timer.elapsed() / 20.0 <<
", " << dist
239 while (timer.elapsed() < 1) {
244 std::cout << type <<
", open, " << timer.elapsed() / count <<
", 0"
250 int main(
int,
char**) {
253 std::string name_base = RMF::internal::get_unique_path();
255 std::cout << name_base << std::endl;
258 const std::string name = name_base +
".rmf";
261 std::pair<std::size_t, std::size_t> sizes = benchmark_create(fh,
"rmf");
262 std::cout <<
"raw, total, " << show_size(sizes.first + sizes.second)
263 <<
", " << (sizes.first + sizes.second) << std::endl;
264 std::cout <<
"raw, frame, " << show_size(sizes.second) <<
", "
265 << sizes.second << std::endl;
269 benchmark_traverse(fh,
"rmf");
270 benchmark_load(fh,
"rmf");
272 benchmark_size(name,
"rmf");
275 const std::string name = name_base +
".rmfz";
278 benchmark_create(fh,
"rmfz");
282 benchmark_traverse(fh,
"rmfz");
283 benchmark_load(fh,
"rmfz");
285 benchmark_size(name,
"rmfz");
287 #if RMF_HAS_DEPRECATED_BACKENDS
289 const std::string name = name_base +
".rmf-hdf5";
292 benchmark_create(fh,
"hdf5");
296 benchmark_traverse(fh,
"hdf5");
297 benchmark_load(fh,
"hdf5");
299 benchmark_size(name,
"hdf5");
306 benchmark_create(fh,
"buffer");
311 std::cout <<
"buffer"
312 <<
", open, " << timer.elapsed() <<
", 0" << std::endl;
313 benchmark_traverse(fh,
"buffer");
314 benchmark_load(fh,
"buffer");
318 catch (
const std::exception& e) {
319 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.