Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/utility/generation_benchmark.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/utility/generation_benchmark.cpp')
-rw-r--r--source/utility/generation_benchmark.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/source/utility/generation_benchmark.cpp b/source/utility/generation_benchmark.cpp
new file mode 100644
index 0000000..f3f2f97
--- /dev/null
+++ b/source/utility/generation_benchmark.cpp
@@ -0,0 +1,81 @@
+#include "StarRootLoader.hpp"
+#include "StarCelestialDatabase.hpp"
+#include "StarWorldTemplate.hpp"
+#include "StarWorldServer.hpp"
+
+using namespace Star;
+
+int main(int argc, char** argv) {
+ try {
+ RootLoader rootLoader({{}, {}, {}, LogLevel::Error, false, {}});
+ rootLoader.addParameter("coordinate", "coordinate", OptionParser::Optional, "world coordinate to test");
+ rootLoader.addParameter("regions", "regions", OptionParser::Optional, "number of regions to generate, default 1000");
+ rootLoader.addParameter("regionsize", "size", OptionParser::Optional, "width / height of each generation region, default 10");
+ rootLoader.addParameter("reportevery", "report regions", OptionParser::Optional, "number of generation regions before each progress report, default 20");
+
+ RootUPtr root;
+ OptionParser::Options options;
+ tie(root, options) = rootLoader.commandInitOrDie(argc, argv);
+
+ coutf("Fully loading root...");
+ root->fullyLoad();
+ coutf(" done\n");
+
+ CelestialMasterDatabase celestialDatabase;
+
+ CelestialCoordinate coordinate;
+ if (auto coordinateOption = options.parameters.maybe("coordinate")) {
+ coordinate = CelestialCoordinate(coordinateOption->first());
+ } else {
+ coordinate = celestialDatabase.findRandomWorld(100, 50, [&](CelestialCoordinate const& coord) {
+ return celestialDatabase.parameters(coord)->isVisitable();
+ }).take();
+ }
+
+ unsigned regionsToGenerate = 1000;
+ if (auto regionsOption = options.parameters.maybe("regions"))
+ regionsToGenerate = lexicalCast<unsigned>(regionsOption->first());
+
+ unsigned regionSize = 10;
+ if (auto regionSizeOption = options.parameters.maybe("regionsize"))
+ regionSize = lexicalCast<unsigned>(regionSizeOption->first());
+
+ unsigned reportEvery = 20;
+ if (auto reportEveryOption = options.parameters.maybe("reportevery"))
+ reportEvery = lexicalCast<unsigned>(reportEveryOption->first());
+
+ coutf("testing generation on coordinate %s\n", coordinate);
+
+ auto worldParameters = celestialDatabase.parameters(coordinate).take();
+ auto worldTemplate = make_shared<WorldTemplate>(worldParameters.visitableParameters(), SkyParameters(), worldParameters.seed());
+
+ auto rand = RandomSource(worldTemplate->worldSeed());
+
+ WorldServer worldServer(move(worldTemplate), File::ephemeralFile());
+ Vec2U worldSize = worldServer.geometry().size();
+
+ double start = Time::monotonicTime();
+ double lastReport = Time::monotonicTime();
+
+ coutf("Starting world generation for %s regions\n", regionsToGenerate);
+
+ for (unsigned i = 0; i < regionsToGenerate; ++i) {
+ if (i != 0 && i % reportEvery == 0) {
+ float gps = reportEvery / (Time::monotonicTime() - lastReport);
+ lastReport = Time::monotonicTime();
+ coutf("[%s] %ss | Generatons Per Second: %s\n", i, Time::monotonicTime() - start, gps);
+ }
+
+ RectI region = RectI::withCenter(Vec2I(rand.randInt(0, worldSize[0]), rand.randInt(0, worldSize[1])), Vec2I::filled(regionSize));
+ worldServer.generateRegion(region);
+ }
+
+ coutf("Finished generating %s regions with size %sx%s in world '%s' in %s seconds", regionsToGenerate, regionSize, regionSize, coordinate, Time::monotonicTime() - start);
+
+ return 0;
+
+ } catch (std::exception const& e) {
+ cerrf("Exception caught: %s\n", outputException(e, true));
+ return 1;
+ }
+}