#include <boost/iterator/iterator_facade.hpp>
#include <boost/version.hpp>
#include <boost/filesystem/operations.hpp>
#if BOOST_VERSION >= 107200
#include <boost/filesystem/directory.hpp>
#endif
#include <exception>
#include <iostream>
#include <chrono>
#include <string>
#include <vector>
namespace {
#ifndef NDEBUG
const int scale = 1;
#else
const int scale = 5;
#endif
std::string show_size(unsigned int sz) {
std::ostringstream oss;
if (sz > 1000000) {
oss << sz / 1000000 << "M";
} else if (sz > 1000) {
oss << sz / 1000 << "k";
} else {
oss << sz << "b";
}
return oss.str();
}
class Timer {
std::chrono::steady_clock::time_point start_time_;
public:
Timer() {
start_time_ = std::chrono::steady_clock::now();
}
double elapsed() const {
auto end_time = std::chrono::steady_clock::now();
auto time_span = std::chrono::duration_cast<
std::chrono::duration<double> >(end_time - start_time_);
return time_span.count();
}
};
void benchmark_size(std::string path, std::string type) {
unsigned int size = 0;
if (boost::filesystem::is_directory(path)) {
for (boost::filesystem::directory_iterator it(path);
it != boost::filesystem::directory_iterator(); it++) {
size += boost::filesystem::file_size(*it);
}
} else {
size = boost::filesystem::file_size(path);
}
std::cout << type << ", size, " << show_size(size) << ", " << size
<< std::endl;
}
std::size_t total_size = 0;
for (unsigned int i = 0; i < 2 * scale; ++i) {
pf.
get(child).set_static_mass(1);
pf.
get(child).set_static_radius(1.0 + i / 18.77);
af.
get(child).set_static_element(7);
total_size += sizeof(int) * 1 + sizeof(float) * 2;
}
return total_size;
}
std::size_t total_size = 0;
for (unsigned int i = 0; i < 60 * scale; ++i) {
std::ostringstream oss;
oss << i;
rf.
get(child).set_static_residue_type(
"cys");
rf.
get(child).set_static_residue_index(i);
total_size += sizeof(int) + 4;
total_size += create_residue(child, af, pf);
}
return total_size;
}
std::size_t total_size = 0;
for (unsigned int i = 0; i < 3 * scale; ++i) {
std::ostringstream oss;
oss << i;
cf.
get(child).set_static_chain_id(oss.str());
total_size += oss.str().size();
total_size += create_chain(child, rf, af, pf);
}
return total_size;
}
int frame) {
std::size_t total_size = 0;
(n.get_index() + 1 + frame) / 19.0,
(n.get_index() + 2 + frame) / 23.0);
ret[0] += v[0];
ret[1] += v[1];
ret[2] += v[2];
total_size += sizeof(float) * 3;
}
return std::make_pair(ret[0] + ret[1] + ret[2], total_size);
}
std::size_t hierarchy_size = create_hierarchy(file);
if (file.
get_node(n).
get_children().empty()) {
atoms.push_back(n);
}
}
return boost::make_tuple(hierarchy_size);
}
double check_value = 0;
std::size_t frame_size = 0;
for (unsigned int i = 0; i < 20; ++i) {
std::pair<double, std::size_t> cur = create_frame(file, ipf, atoms, i);
check_value += cur.first;
frame_size += cur.second;
}
return boost::make_tuple(check_value, frame_size);
}
double ret = 0;
do {
queue.pop_back();
if (ipcf.get_is(cur)) {
ret += ipcf.get(cur).get_radius();
}
queue.insert(queue.end(), children.begin(), children.end());
} while (!queue.empty());
return ret;
}
file.
set_current_frame(fr);
v[0] += cur[0];
v[1] += cur[1];
v[2] += cur[2];
}
}
return v[0] + v[1] + v[2];
}
std::string type) {
Timer timer;
boost::tuple<std::size_t> cur = create(file, atoms);
std::cout << type << ", create, " << timer.elapsed() << ", " << cur.get<0>()
<< std::endl;
Timer frame_timer;
boost::tuple<double, std::size_t> frames = create_frames(file, atoms);
std::cout << type << ", create frame, " << frame_timer.elapsed() / 20.0
<< ", " << frames.get<0>() << std::endl;
return std::make_pair(cur.get<0>(), frames.get<1>());
}
Timer timer;
double count = 0;
double t;
while (timer.elapsed() < 1) {
t = traverse(file);
++count;
}
std::cout << type << ", traverse, " << timer.elapsed() / count << ", " << t
<< std::endl;
}
if (ipcf.
get_is(file.get_node(n))) nodes.push_back(n);
}
Timer timer;
double dist = load(file, nodes);
std::cout << type << ", load, " << timer.elapsed() / 20.0 << ", " << dist
<< std::endl;
}
Timer timer;
double count = 0;
while (timer.elapsed() < 1) {
++count;
}
std::cout << type << ", open, " << timer.elapsed() / count << ", 0"
<< std::endl;
return ret;
}
}
int main(int, char**) {
try {
std::string name_base = RMF::internal::get_unique_path();
#ifndef NDEBUG
std::cout << name_base << std::endl;
#endif
{
const std::string name = name_base + ".rmf";
{
std::pair<std::size_t, std::size_t> sizes = benchmark_create(fh, "rmf");
std::cout << "raw, total, " << show_size(sizes.first + sizes.second)
<< ", " << (sizes.first + sizes.second) << std::endl;
std::cout << "raw, frame, " << show_size(sizes.second) << ", "
<< sizes.second << std::endl;
}
{
benchmark_traverse(fh, "rmf");
benchmark_load(fh, "rmf");
}
benchmark_size(name, "rmf");
}
{
const std::string name = name_base + ".rmfz";
{
benchmark_create(fh, "rmfz");
}
{
benchmark_traverse(fh, "rmfz");
benchmark_load(fh, "rmfz");
}
benchmark_size(name, "rmfz");
}
#if RMF_HAS_DEPRECATED_BACKENDS
{
const std::string name = name_base + ".rmf-hdf5";
{
benchmark_create(fh, "hdf5");
}
{
benchmark_traverse(fh, "hdf5");
benchmark_load(fh, "hdf5");
}
benchmark_size(name, "hdf5");
}
#endif
{
{
benchmark_create(fh, "buffer");
}
{
Timer timer;
std::cout << "buffer"
<< ", open, " << timer.elapsed() << ", 0" << std::endl;
benchmark_traverse(fh, "buffer");
benchmark_load(fh, "buffer");
}
}
}
catch (const std::exception& e) {
std::cerr << "Exception thrown: " << e.what() << std::endl;
}
return 0;
}