dfhack/tools/supported/expbench.cpp

105 lines
2.7 KiB
C++

2009-09-13 18:02:46 -06:00
// This program exports the entire map from DF. Takes roughly 6.6 seconds for 1000 cycles on my Linux machine. ~px
#include <iostream>
#include <vector>
2009-10-30 03:01:14 -06:00
#include <ctime>
2010-02-28 18:06:22 -07:00
#include <sstream>
#include <string>
2009-09-13 18:02:46 -06:00
using namespace std;
2010-05-25 22:48:23 -06:00
#include <DFHack.h>
#include "termutil.h"
2010-02-28 18:06:22 -07:00
void print_progress (int current, int total)
{
if(total < 100)
{
cout << "\b" << current << " / " << total << " %\xd" << std::flush;
}
else
{
if( current % (total/100) == 0 )
{
int percentage = current / (total/100);
// carridge return, not line feed, so percentage, less console spam :)
cout << "\b" << percentage << " %\xd" << std::flush; // and a flush for good measure
}
}
}
int main (int numargs, char** args)
2009-09-13 18:02:46 -06:00
{
bool temporary_terminal = TemporaryTerminal();
2009-10-30 03:01:14 -06:00
time_t start, end;
double time_diff;
2010-02-28 18:06:22 -07:00
unsigned int iterations = 0;
if (numargs == 2)
{
istringstream input (args[1],istringstream::in);
input >> iterations;
}
if(iterations == 0)
iterations = 1000;
2009-09-13 18:02:46 -06:00
uint32_t x_max,y_max,z_max;
uint32_t num_blocks = 0;
uint64_t bytes_read = 0;
2010-03-04 16:05:01 -07:00
DFHack::mapblock40d Block;
2010-04-04 16:48:19 -06:00
DFHack::Maps *Maps = 0;
2010-05-23 15:06:10 -06:00
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context *DF;
try
2009-09-13 18:02:46 -06:00
{
2010-05-23 15:06:10 -06:00
DF = DFMgr.getSingleContext();
DF->Attach();
Maps = DF->getMaps();
}
catch (exception& e)
{
cerr << e.what() << endl;
if(temporary_terminal)
cin.ignore();
2009-09-13 18:02:46 -06:00
return 1;
}
2009-10-30 03:01:14 -06:00
time(&start);
2010-02-28 18:06:22 -07:00
cout << "doing " << iterations << " iterations" << endl;
for(uint32_t i = 0; i< iterations;i++)
2009-09-13 18:02:46 -06:00
{
2010-02-28 18:06:22 -07:00
print_progress (i, iterations);
2010-04-04 16:48:19 -06:00
if(!Maps->Start())
2010-01-11 11:57:57 -07:00
break;
2010-04-04 16:48:19 -06:00
Maps->getSize(x_max,y_max,z_max);
2009-10-28 16:40:21 -06:00
for(uint32_t x = 0; x< x_max;x++)
{
for(uint32_t y = 0; y< y_max;y++)
2009-09-13 18:02:46 -06:00
{
2009-10-28 16:40:21 -06:00
for(uint32_t z = 0; z< z_max;z++)
2009-09-13 18:02:46 -06:00
{
2010-04-04 16:48:19 -06:00
if(Maps->isValidBlock(x,y,z))
2009-10-28 16:40:21 -06:00
{
2010-04-04 16:48:19 -06:00
Maps->ReadBlock40d(x, y, z, &Block);
2009-10-28 16:40:21 -06:00
num_blocks ++;
2010-03-04 16:05:01 -07:00
bytes_read += sizeof(DFHack::mapblock40d);
2009-10-28 16:40:21 -06:00
}
2009-09-13 18:02:46 -06:00
}
}
}
2010-04-04 16:48:19 -06:00
Maps->Finish();
2009-09-13 18:02:46 -06:00
}
2010-05-23 15:06:10 -06:00
DF->Detach();
2009-10-30 03:01:14 -06:00
time(&end);
time_diff = difftime(end, start);
2009-09-13 18:02:46 -06:00
cout << num_blocks << " blocks read" << endl;
cout << bytes_read / (1024 * 1024) << " MB" << endl;
2009-10-30 03:01:14 -06:00
cout << "map export tests done in " << time_diff << " seconds." << endl;
if(temporary_terminal)
{
2010-02-28 18:06:22 -07:00
cout << "Done. Press any key to continue" << endl;
cin.ignore();
}
2009-09-13 18:02:46 -06:00
return 0;
}