Skip to content

Commit

Permalink
Remove boost filesystem usage
Browse files Browse the repository at this point in the history
Replaced with std::experimental::filesystem

Removed boost as a dependency, and removed from travis.

Updated benchmarks.

Signed-off-by: Mark Beckwith <wythe@intrig.com>
  • Loading branch information
wythe committed Aug 28, 2019
1 parent dadbbaa commit da24a35
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 150 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.PHONY: all clean realclean check test update get-deps install uninstall check-install
.PHONY: tags

all: include/xenon/ict/ict.h build
ninja -C build
Expand Down Expand Up @@ -45,4 +46,4 @@ update:

get-deps:
sudo apt-get update
sudo apt-get install -y libboost-all-dev meson
sudo apt-get install -y meson
6 changes: 0 additions & 6 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ project('xenon', 'cpp',

inc = include_directories(['include'])
xenon_inc = include_directories(['src'])
boost_dep = dependency('boost', modules : ['system', 'filesystem'])

if not boost_dep.found()
error('no boost')
endif

subdir('xspx')
subdir('include')
subdir('src')
Expand Down
113 changes: 46 additions & 67 deletions perf/decode.cpp
Original file line number Diff line number Diff line change
@@ -1,88 +1,92 @@
//-- Copyright 2016 Intrig
//-- See https://github.com/intrig/xenon for license.
#include <experimental/filesystem>
#include <iostream>
#include <vector>
#include <xenon/xenon.h>
#include <xenon/xddl_code.h>
#include <xenon/ict/command.h>
#include <boost/filesystem.hpp>
#include <xenon/xddl_code.h>
#include <xenon/xenon.h>

namespace bf = boost::filesystem;
using std::cout;
namespace fs = std::experimental::filesystem;
using std::cerr;
using std::cout;

template <typename Op>
void iterate(int n, Op op) {
template <typename Op> void iterate(int n, Op op) {
ict::timer time;
time.start();
for (int i = 0; i < n; ++i) op();
for (int i = 0; i < n; ++i)
op();
time.stop();
cerr << time << '\n';
};

void load_all_xddl(const bf::path & dir, xenon::spec_server & specs) {
bf::directory_iterator end_itr;
for (auto i = bf::directory_iterator(dir); i != end_itr; ++i) {
if (bf::is_directory(i->path())) load_all_xddl(i->path(), specs);
else if (bf::extension(i->path()) == ".xddl") {
void load_all_xddl(const fs::path &dir, xenon::spec_server &specs) {
fs::directory_iterator end_itr;
for (auto i = fs::directory_iterator(dir); i != end_itr; ++i) {
if (fs::is_directory(i->path()))
load_all_xddl(i->path(), specs);
else if (i->path().extension() == ".xddl") {
specs.add_spec(i->path().string());
}
}
}

void load_test(const std::string & root, int n) {
iterate(n, [&](){
void load_test(const std::string &root, int n) {
iterate(n, [&]() {
xenon::spec_server specs;
auto p = bf::path(root);
auto p = fs::path(root);
load_all_xddl(p, specs);
});
}

void decode(xenon::spec_server & specs, const ict::bitstring & bits, int n) {
void decode(xenon::spec_server &specs, const ict::bitstring &bits, int n) {
xenon::message m;
iterate(n, [&](){ m = xenon::parse(specs, bits); });
iterate(n, [&]() { m = xenon::parse(specs, bits); });
}

void decode_xml(xenon::spec_server & specs, const ict::bitstring & bits, int n) {
void decode_xml(xenon::spec_server &specs, const ict::bitstring &bits, int n) {
auto m = xenon::parse(specs, bits);
iterate(n, [&](){
auto s = xenon::to_xml(m);
});
iterate(n, [&]() { auto s = xenon::to_xml(m); });
}

void decode_pretty(xenon::spec_server & specs, const ict::bitstring & bits, int n) {
void decode_pretty(xenon::spec_server &specs, const ict::bitstring &bits,
int n) {
auto m = xenon::parse(specs, bits);
iterate(n, [&](){
iterate(n, [&]() {
xenon::xml_type xml(xenon::to_xml(m));
auto x = xml.str();
});
}

int main(int argc, char** argv) {
int main(int argc, char **argv) {
try {
int iterations = 3000;
bool pretty = false;
bool xml = false;
bool load = false;
ict::command line("xmlperf", "Decode xenon::message to xml", "xmlperf xddl-dir");
line.add(ict::option("load", 'l', "Load all xddl files", [&]{ load = true; }));
line.add(ict::option("xml", 'x', "Convert to flat xml", [&]{ xml = true; }));
line.add(ict::option("pretty", 'p', "Convert to pretty xml", [&]{ pretty = true; }));
line.add(ict::option("iterations", 'i', "Number of iterations", std::to_string(iterations),
[&](const std::string & i) {
iterations = std::stoi(i);
}));
ict::command line("xmlperf", "Decode xenon::message to xml",
"xmlperf xddl-dir");
line.add(ict::option("load", 'l', "Load all xddl files",
[&] { load = true; }));
line.add(ict::option("xml", 'x', "Convert to flat xml",
[&] { xml = true; }));
line.add(ict::option("pretty", 'p', "Convert to pretty xml",
[&] { pretty = true; }));
line.add(ict::option(
"iterations", 'i', "Number of iterations",
std::to_string(iterations),
[&](const std::string &i) { iterations = std::stoi(i); }));

line.parse(argc, argv);
if (line.targets.size() != 1) IT_FATAL("Exactly one argument is required, the path to the xddl directory.");

if (line.targets.size() != 1)
IT_FATAL("Exactly one argument is required, the path to the xddl "
"directory.");

auto icd = line.targets[0] + "/icd.xddl";
xenon::spec_server specs(icd);
auto bits = ict::bitstring("0101046B102C000114E03003603800203801C03801E03801F030037030002030"
"00903000603000E0300120300130380000300110300030380080300200300210"
"3001903001603000F03000703000403000C03000503000D1A03C9E16C18070DE"
"2C7CFF3C7CC1001E00E01C000389");
auto bits = ict::bitstring(
"0101046B102C000114E03003603800203801C03801E03801F030037030002030"
"00903000603000E0300120300130380000300110300030380080300200300210"
"3001903001603000F03000703000403000C03000503000D1A03C9E16C18070DE"
"2C7CFF3C7CC1001E00E01C000389");

if (load) {
load_test(line.targets[0], iterations);
Expand All @@ -93,32 +97,7 @@ int main(int argc, char** argv) {
} else {
decode(specs, bits, iterations);
}

#if 0
auto msg = xenon::parse(doc, "0101046B102C000114E03003603800203801C03801E03801F030037030002030"
"00903000603000E0300120300130380000300110300030380080300200300210"
"3001903001603000F03000703000403000C03000503000D1A03C9E16C18070DE"
"2C7CFF3C7CC1001E00E01C000389");

if (pretty) {
time.start();
for (auto i=0; i < iterations; ++i) {
xenon::xml_type xml(xenon::to_xml(msg));
auto x = xml.str();
}
time.stop();
} else {
time.start();
for (auto i=0; i < iterations; ++i) {
auto s = xenon::to_xml(msg);
}
time.stop();
}
cerr << time << '\n';
#endif


} catch (std::exception & e) {
} catch (std::exception &e) {
cerr << e.what() << '\n';
return 1;
}
Expand Down
53 changes: 28 additions & 25 deletions perf/loadperf.cpp
Original file line number Diff line number Diff line change
@@ -1,57 +1,60 @@
//-- Copyright 2016 Intrig
//-- See https://github.com/intrig/xenon for license.
#include "loadperf.h"

#include <boost/filesystem.hpp>
#include <ict/command.h>
#include <experimental/filesystem>
#include <xenon/ict/command.h>
#include <xenon/xenon.h>

namespace bf = boost::filesystem;
namespace fs = std::experimental::filesystem;
using std::cout;

void load_all_xddl(const bf::path & dir, xenon::spec_server & specs) {
if (!exists(dir)) return;
bf::directory_iterator end_itr;
for (auto i = bf::directory_iterator(dir); i != end_itr; ++i) {
if (bf::is_directory(i->path())) load_all_xddl(i->path(), specs);
else if (bf::extension(i->path()) == ".xddl") {
void load_all_xddl(const fs::path &dir, xenon::spec_server &specs) {
if (!exists(dir))
return;
fs::directory_iterator end_itr;
for (auto i = fs::directory_iterator(dir); i != end_itr; ++i) {
if (fs::is_directory(i->path()))
load_all_xddl(i->path(), specs);
else if (i->path().extension() == ".xddl") {
specs.add_spec(i->path().string());
}
}
}

void load_unit::load_all_specs() {
for (auto i = 0; i < iterations; ++i) {
auto p = bf::path(root);
auto p = fs::path(root);
xenon::spec_server specs;
try {
load_all_xddl(p, specs);
} catch (const bf::filesystem_error& ex) {
IT_FORCE_ASSERT("filesystem error: " << ex.what());
} catch (const std::exception & ex) {
IT_FORCE_ASSERT(ex.what());
} catch (const fs::filesystem_error &ex) {
IT_FORCE_ASSERT("filesystem error: " << ex.what());
} catch (const std::exception &ex) {
IT_FORCE_ASSERT(ex.what());
}
}
}

int main (int argc, char **argv) {
int main(int argc, char **argv) {
try {
load_unit test;

ict::command line("xmlperf", "Loading XDDL performance", "xmlperf xddl-dir");
line.add(ict::option("iterations", 'i', "Number of iterations", std::to_string(test.iterations),
[&](const std::string & i) {
test.iterations = std::stoi(i);
}));
ict::command line("xmlperf", "Loading XDDL performance",
"xmlperf xddl-dir");
line.add(ict::option(
"iterations", 'i', "Number of iterations",
std::to_string(test.iterations),
[&](const std::string &i) { test.iterations = std::stoi(i); }));
line.add_note("load the entire XDDL tree");

line.parse(argc, argv);
if (line.targets.size() != 1) IT_FATAL("Exactly one argument is required, the path to the xddl directory.");
if (line.targets.size() != 1)
IT_FATAL("Exactly one argument is required, the path to the xddl "
"directory.");
test.root = line.targets[0];

ict::unit_test<load_unit> ut(&test);
return ut.run();
} catch (std::exception & e) {
} catch (std::exception &e) {
std::cerr << e.what() << '\n';
return 1;
}
Expand Down
11 changes: 3 additions & 8 deletions perf/loadperf.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#pragma once
//-- Copyright 2016 Intrig
//-- See https://github.com/intrig/xenon for license.

#include <ict/unit.h>
#include <xenon/ict/unit.h>
#include <xenon/xenon.h>

class load_unit {
public:

void register_tests(ict::unit_test<load_unit> & ut) {
public:
void register_tests(ict::unit_test<load_unit> &ut) {
ut.add(&load_unit::load_all_specs);
}

Expand All @@ -18,4 +14,3 @@ class load_unit {
int iterations = 5;
std::string root;
};

48 changes: 26 additions & 22 deletions perf/meson.build
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
if boost_dep.found()
decodeperf_exe = executable('decodeperf', 'decode.cpp', xddl_h,
include_directories : inc,
dependencies : boost_dep,
link_with : xenon_lib)
decodeperf_exe = executable('decodeperf', 'decode.cpp', xddl_h,
include_directories : inc,
link_args : '-lstdc++fs',
link_with : xenon_lib)

benchmark('loading xddl', decodeperf_exe,
workdir : meson.source_root(),
args : ['-i', '5', '--load', 'xddl']
)
loadperf_exe = executable('loadperf', 'loadperf.cpp', xddl_h,
include_directories : inc,
link_args : '-lstdc++fs',
link_with : xenon_lib)

benchmark('decoding message', decodeperf_exe,
workdir : meson.source_root(),
args : ['-i', '10000', 'xddl']
)
benchmark('loading xddl', decodeperf_exe,
workdir : meson.source_root(),
args : ['-i', '5', '--load', 'xddl'])

benchmark('flat xml', decodeperf_exe,
workdir : meson.source_root(),
args : ['--xml', 'xddl']
)
benchmark('decoding message', decodeperf_exe,
workdir : meson.source_root(),
args : ['-i', '10000', 'xddl'])

benchmark('flat xml', decodeperf_exe,
workdir : meson.source_root(),
args : ['--xml', 'xddl'])

benchmark('pretty xml', decodeperf_exe,
workdir : meson.source_root(),
args : ['--pretty', 'xddl'])

benchmark('load xddl', loadperf_exe,
workdir : meson.source_root(),
args : 'xddl')

benchmark('pretty xml', decodeperf_exe,
workdir : meson.source_root(),
args : ['--pretty', 'xddl']
)
endif
21 changes: 9 additions & 12 deletions unit/document/loadunit.cpp
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
//-- Copyright 2016 Intrig
//-- See https://github.com/intrig/xenon for license.
#include "loadunit.h"

#include <boost/filesystem.hpp>
#include <experimental/filesystem>
#include <xenon/spec_server.h>

namespace bf = boost::filesystem;
namespace fs = std::experimental::filesystem;
using std::cout;

void load_unit::sanity() {
}

void load_all_xddl(const bf::path & dir, xenon::spec_server & specs) {
void load_all_xddl(const fs::path & dir, xenon::spec_server & specs) {
if (!exists(dir))
return;
bf::directory_iterator end_itr;
for (auto i = bf::directory_iterator(dir); i != end_itr; ++i) {
if (bf::is_directory(i->path()))
fs::directory_iterator end_itr;
for (auto i = fs::directory_iterator(dir); i != end_itr; ++i) {
if (fs::is_directory(i->path()))
load_all_xddl(i->path(), specs);
else if (bf::extension(i->path()) == ".xddl")
else if (i->path().extension() == ".xddl")
specs.add_spec(i->path().string());
}
}

void load_unit::load_all_specs() {
xenon::spec_server specs;
auto p = bf::path("xddl");
auto p = fs::path("xddl");
try {
load_all_xddl(p, specs);
} catch (const bf::filesystem_error& ex) {
} catch (const fs::filesystem_error& ex) {
IT_FORCE_ASSERT("filesystem error: " << ex.what());
} catch (const std::exception & ex) {
IT_FORCE_ASSERT(ex.what());
Expand Down
Loading

0 comments on commit da24a35

Please sign in to comment.