Skip to content

Commit

Permalink
3822: Format common
Browse files Browse the repository at this point in the history
  • Loading branch information
kduske committed Nov 13, 2021
1 parent 143764e commit d195c08
Show file tree
Hide file tree
Showing 1,143 changed files with 159,255 additions and 148,232 deletions.
67 changes: 41 additions & 26 deletions common/benchmark/src/AABBTreeBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include "IO/Reader.h"
#include "IO/TestParserStatus.h"
#include "IO/WorldReader.h"
#include "Model/BrushNode.h"
#include "Model/BrushFace.h"
#include "Model/BrushNode.h"
#include "Model/EntityNode.h"
#include "Model/EntityProperties.h"
#include "Model/GroupNode.h"
Expand All @@ -37,36 +37,51 @@

#include <vecmath/bbox.h>

#include "BenchmarkUtils.h"
#include "../../test/src/Catch2.h"
#include "BenchmarkUtils.h"

namespace TrenchBroom {
using AABB = AABBTree<double, 3, Model::Node*>;
using BOX = AABB::Box;
using AABB = AABBTree<double, 3, Model::Node*>;
using BOX = AABB::Box;

TEST_CASE("AABBTreeBenchmark.benchBuildTree", "[AABBTreeBenchmark]") {
const auto mapPath = IO::Disk::getCurrentWorkingDir() + IO::Path("fixture/benchmark/AABBTree/ne_ruins.map");
const auto file = IO::Disk::openFile(mapPath);
auto fileReader = file->reader().buffer();
TEST_CASE("AABBTreeBenchmark.benchBuildTree", "[AABBTreeBenchmark]") {
const auto mapPath =
IO::Disk::getCurrentWorkingDir() + IO::Path("fixture/benchmark/AABBTree/ne_ruins.map");
const auto file = IO::Disk::openFile(mapPath);
auto fileReader = file->reader().buffer();

IO::TestParserStatus status;
IO::WorldReader worldReader(fileReader.stringView(), Model::MapFormat::Standard, {});
IO::TestParserStatus status;
IO::WorldReader worldReader(fileReader.stringView(), Model::MapFormat::Standard, {});

const vm::bbox3 worldBounds(8192.0);
auto world = worldReader.read(worldBounds, status);
const vm::bbox3 worldBounds(8192.0);
auto world = worldReader.read(worldBounds, status);

std::vector<AABB> trees(100);
timeLambda([&world, &trees]() {
for (auto& tree : trees) {
world->accept(kdl::overload(
[] (auto&& thisLambda, Model::WorldNode* world_) { world_->visitChildren(thisLambda); },
[] (auto&& thisLambda, Model::LayerNode* layer) { layer->visitChildren(thisLambda); },
[] (auto&& thisLambda, Model::GroupNode* group) { group->visitChildren(thisLambda); },
[&](auto&& thisLambda, Model::EntityNode* entity) { entity->visitChildren(thisLambda); tree.insert(entity->physicalBounds(), entity); },
[&](Model::BrushNode* brush) { tree.insert(brush->physicalBounds(), brush); },
[&](Model::PatchNode* patch) { tree.insert(patch->physicalBounds(), patch); }
));
}
}, "Add objects to AABB tree");
}
std::vector<AABB> trees(100);
timeLambda(
[&world, &trees]() {
for (auto& tree : trees) {
world->accept(kdl::overload(
[](auto&& thisLambda, Model::WorldNode* world_) {
world_->visitChildren(thisLambda);
},
[](auto&& thisLambda, Model::LayerNode* layer) {
layer->visitChildren(thisLambda);
},
[](auto&& thisLambda, Model::GroupNode* group) {
group->visitChildren(thisLambda);
},
[&](auto&& thisLambda, Model::EntityNode* entity) {
entity->visitChildren(thisLambda);
tree.insert(entity->physicalBounds(), entity);
},
[&](Model::BrushNode* brush) {
tree.insert(brush->physicalBounds(), brush);
},
[&](Model::PatchNode* patch) {
tree.insert(patch->physicalBounds(), patch);
}));
}
},
"Add objects to AABB tree");
}
} // namespace TrenchBroom
18 changes: 8 additions & 10 deletions common/benchmark/src/BenchmarkUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@
#endif

// the noinline is so you can see the timeLambda when profiling
template<class L>
TB_NOINLINE static void timeLambda(L&& lambda, const std::string& message) {
const auto start = std::chrono::high_resolution_clock::now();
lambda();
const auto end = std::chrono::high_resolution_clock::now();

printf("Time elapsed for '%s': %fms\n", message.c_str(),
std::chrono::duration<double>(end - start).count() * 1000.0);
template <class L> TB_NOINLINE static void timeLambda(L&& lambda, const std::string& message) {
const auto start = std::chrono::high_resolution_clock::now();
lambda();
const auto end = std::chrono::high_resolution_clock::now();

printf(
"Time elapsed for '%s': %fms\n", message.c_str(),
std::chrono::duration<double>(end - start).count() * 1000.0);
}


30 changes: 16 additions & 14 deletions common/benchmark/src/IO/TestParserStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,24 @@
#include <string>

namespace TrenchBroom {
namespace IO {
NullLogger TestParserStatus::_logger;
namespace IO {
NullLogger TestParserStatus::_logger;

TestParserStatus::TestParserStatus() : ParserStatus(_logger, "") {}
TestParserStatus::TestParserStatus()
: ParserStatus(_logger, "") {}

size_t TestParserStatus::countStatus(LogLevel level) const {
const auto it = m_statusCounts.find(level);
if (it == std::end(m_statusCounts))
return 0;
return it->second;
}
size_t TestParserStatus::countStatus(LogLevel level) const {
const auto it = m_statusCounts.find(level);
if (it == std::end(m_statusCounts))
return 0;
return it->second;
}

void TestParserStatus::doProgress(const double) {}
void TestParserStatus::doProgress(const double) {}

void TestParserStatus::doLog(const LogLevel level, const std::string& /* str */) {
m_statusCounts[level]++; // unknown map values are value constructed, which initializes to 0 for size_t
}
}
void TestParserStatus::doLog(const LogLevel level, const std::string& /* str */) {
m_statusCounts[level]++; // unknown map values are value constructed, which initializes to 0 for
// size_t
}
} // namespace IO
} // namespace TrenchBroom
38 changes: 20 additions & 18 deletions common/benchmark/src/IO/TestParserStatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,29 @@

#pragma once

#include "Logger.h"
#include "IO/ParserStatus.h"
#include "Logger.h"

#include <map>
#include <string>

namespace TrenchBroom {
namespace IO {
class TestParserStatus : public ParserStatus {
private:
static NullLogger _logger;
using StatusCounts = std::map<LogLevel, size_t>;
StatusCounts m_statusCounts;
public:
TestParserStatus();
public:
size_t countStatus(LogLevel level) const;
private:
void doProgress(double progress) override;
void doLog(LogLevel level, const std::string& str) override;
};
}
}

namespace IO {
class TestParserStatus : public ParserStatus {
private:
static NullLogger _logger;
using StatusCounts = std::map<LogLevel, size_t>;
StatusCounts m_statusCounts;

public:
TestParserStatus();

public:
size_t countStatus(LogLevel level) const;

private:
void doProgress(double progress) override;
void doLog(LogLevel level, const std::string& str) override;
};
} // namespace IO
} // namespace TrenchBroom
Loading

0 comments on commit d195c08

Please sign in to comment.