mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 00:33:09 +00:00
Tidy up benchmark.cpp
No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
dab1cd8af9
commit
ff1ecb5d6c
2 changed files with 26 additions and 31 deletions
|
@ -49,13 +49,12 @@ static const string Defaults[] = {
|
||||||
|
|
||||||
|
|
||||||
/// benchmark() runs a simple benchmark by letting Stockfish analyze a set
|
/// benchmark() runs a simple benchmark by letting Stockfish analyze a set
|
||||||
/// of positions for a given limit each. There are five parameters; the
|
/// of positions for a given limit each. There are five parameters; the
|
||||||
/// transposition table size, the number of search threads that should
|
/// transposition table size, the number of search threads that should
|
||||||
/// be used, the limit value spent for each position (optional, default
|
/// be used, the limit value spent for each position (optional, default is
|
||||||
/// is ply 12), an optional file name where to look for positions in fen
|
/// depth 12), an optional file name where to look for positions in fen
|
||||||
/// format (default are the BenchmarkPositions defined above) and the type
|
/// format (defaults are the positions defined above) and the type of the
|
||||||
/// of the limit value: depth (default), time in secs or number of nodes.
|
/// limit value: depth (default), time in secs or number of nodes.
|
||||||
/// The analysis is written to a file named bench.txt.
|
|
||||||
|
|
||||||
void benchmark(int argc, char* argv[]) {
|
void benchmark(int argc, char* argv[]) {
|
||||||
|
|
||||||
|
@ -64,10 +63,6 @@ void benchmark(int argc, char* argv[]) {
|
||||||
int64_t totalNodes;
|
int64_t totalNodes;
|
||||||
int time;
|
int time;
|
||||||
|
|
||||||
// Load default positions
|
|
||||||
for (int i = 0; !Defaults[i].empty(); i++)
|
|
||||||
fenList.push_back(Defaults[i]);
|
|
||||||
|
|
||||||
// Assign default values to missing arguments
|
// Assign default values to missing arguments
|
||||||
string ttSize = argc > 2 ? argv[2] : "128";
|
string ttSize = argc > 2 ? argv[2] : "128";
|
||||||
string threads = argc > 3 ? argv[3] : "1";
|
string threads = argc > 3 ? argv[3] : "1";
|
||||||
|
@ -87,28 +82,27 @@ void benchmark(int argc, char* argv[]) {
|
||||||
else
|
else
|
||||||
limits.maxDepth = atoi(valStr.c_str());
|
limits.maxDepth = atoi(valStr.c_str());
|
||||||
|
|
||||||
// Do we need to load positions from a given FEN file ?
|
// Do we need to load positions from a given FEN file?
|
||||||
if (fenFile != "default")
|
if (fenFile != "default")
|
||||||
{
|
{
|
||||||
string fen;
|
string fen;
|
||||||
ifstream f(fenFile.c_str());
|
ifstream f(fenFile.c_str());
|
||||||
|
|
||||||
if (f.is_open())
|
if (!f.is_open())
|
||||||
{
|
{
|
||||||
fenList.clear();
|
cerr << "Unable to open file " << fenFile << endl;
|
||||||
|
|
||||||
while (getline(f, fen))
|
|
||||||
if (!fen.empty())
|
|
||||||
fenList.push_back(fen);
|
|
||||||
|
|
||||||
f.close();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cerr << "Unable to open FEN file " << fenFile << endl;
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (getline(f, fen))
|
||||||
|
if (!fen.empty())
|
||||||
|
fenList.push_back(fen);
|
||||||
|
|
||||||
|
f.close();
|
||||||
}
|
}
|
||||||
|
else // Load default positions
|
||||||
|
for (int i = 0; !Defaults[i].empty(); i++)
|
||||||
|
fenList.push_back(Defaults[i]);
|
||||||
|
|
||||||
// Ok, let's start the benchmark !
|
// Ok, let's start the benchmark !
|
||||||
totalNodes = 0;
|
totalNodes = 0;
|
||||||
|
@ -124,9 +118,11 @@ void benchmark(int argc, char* argv[]) {
|
||||||
if (valType == "perft")
|
if (valType == "perft")
|
||||||
{
|
{
|
||||||
int64_t cnt = perft(pos, limits.maxDepth * ONE_PLY);
|
int64_t cnt = perft(pos, limits.maxDepth * ONE_PLY);
|
||||||
totalNodes += cnt;
|
|
||||||
|
|
||||||
cerr << "\nPerft " << limits.maxDepth << " nodes counted: " << cnt << endl;
|
cerr << "\nPerft " << limits.maxDepth
|
||||||
|
<< " nodes counted: " << cnt << endl;
|
||||||
|
|
||||||
|
totalNodes += cnt;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -50,9 +50,8 @@ bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// stringify() converts a numeric value of type T to a std::string
|
// An helper to convert an integer value to a std::string
|
||||||
template<typename T>
|
static string int_to_string(int v) {
|
||||||
static string stringify(const T& v) {
|
|
||||||
|
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
ss << v;
|
ss << v;
|
||||||
|
@ -100,10 +99,10 @@ OptionsMap::OptionsMap() {
|
||||||
UCIOption& thr = o["Threads"];
|
UCIOption& thr = o["Threads"];
|
||||||
UCIOption& msd = o["Minimum Split Depth"];
|
UCIOption& msd = o["Minimum Split Depth"];
|
||||||
|
|
||||||
thr.defaultValue = thr.currentValue = stringify(cpu_count());
|
thr.defaultValue = thr.currentValue = int_to_string(cpu_count());
|
||||||
|
|
||||||
if (cpu_count() >= 8)
|
if (cpu_count() >= 8)
|
||||||
msd.defaultValue = msd.currentValue = stringify(7);
|
msd.defaultValue = msd.currentValue = int_to_string(7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -142,7 +141,7 @@ UCIOption::UCIOption(bool def, string t) : type(t), minValue(0), maxValue(0), id
|
||||||
{ defaultValue = currentValue = (def ? "true" : "false"); }
|
{ defaultValue = currentValue = (def ? "true" : "false"); }
|
||||||
|
|
||||||
UCIOption::UCIOption(int def, int minv, int maxv) : type("spin"), minValue(minv), maxValue(maxv), idx(Options.size())
|
UCIOption::UCIOption(int def, int minv, int maxv) : type("spin"), minValue(minv), maxValue(maxv), idx(Options.size())
|
||||||
{ defaultValue = currentValue = stringify(def); }
|
{ defaultValue = currentValue = int_to_string(def); }
|
||||||
|
|
||||||
|
|
||||||
/// set_value() updates currentValue of the Option object. Normally it's up to
|
/// set_value() updates currentValue of the Option object. Normally it's up to
|
||||||
|
|
Loading…
Add table
Reference in a new issue