And also simplify a lot the code.
No functional change.
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
-const string BenchmarkPositions[] = {
+static const string BenchmarkPositions[] = {
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq -",
"8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - -",
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq -",
"8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - -",
void benchmark(const string& commandLine) {
void benchmark(const string& commandLine) {
- istringstream csVal(commandLine);
istringstream csStr(commandLine);
istringstream csStr(commandLine);
- string ttSize, threads, fileName, limitType, timFile;
+ vector<string> positions;
+ string ttSize, threads, limit, posFile, limitType;
int val, secsPerPos, maxDepth, maxNodes;
int val, secsPerPos, maxDepth, maxNodes;
- csStr >> ttSize;
- csVal >> val;
- if (val < 4 || val > 1024)
- {
- cerr << "The hash table size must be between 4 and 1024" << endl;
- Application::exit_with_failure();
- }
- csStr >> threads;
- csVal >> val;
- if (val < 1 || val > MAX_THREADS)
- {
- cerr << "The number of threads must be between 1 and " << MAX_THREADS << endl;
- Application::exit_with_failure();
- }
+ csStr >> ttSize >> threads >> limit >> posFile >> limitType;
+
Options["Hash"].set_value(ttSize);
Options["Threads"].set_value(threads);
Options["OwnBook"].set_value("false");
Options["Use Search Log"].set_value("true");
Options["Search Log Filename"].set_value("bench.txt");
Options["Hash"].set_value(ttSize);
Options["Threads"].set_value(threads);
Options["OwnBook"].set_value("false");
Options["Use Search Log"].set_value("true");
Options["Search Log Filename"].set_value("bench.txt");
- csVal >> val;
- csVal >> fileName;
- csVal >> limitType;
- csVal >> timFile;
-
secsPerPos = maxDepth = maxNodes = 0;
secsPerPos = maxDepth = maxNodes = 0;
+ val = atoi(limit.c_str());
- if (limitType == "time")
- secsPerPos = val * 1000;
- else if (limitType == "depth" || limitType == "perft")
+ if (limitType == "depth" || limitType == "perft")
+ else if (limitType == "time")
+ secsPerPos = val * 1000;
- vector<string> positions;
-
- if (fileName != "default")
+ if (posFile != "default")
- ifstream fenFile(fileName.c_str());
+ ifstream fenFile(posFile.c_str());
if (!fenFile.is_open())
{
if (!fenFile.is_open())
{
- cerr << "Unable to open positions file " << fileName << endl;
+ cerr << "Unable to open positions file " << posFile << endl;
Application::exit_with_failure();
}
string pos;
Application::exit_with_failure();
}
string pos;
for (int i = 0; i < 16; i++)
positions.push_back(string(BenchmarkPositions[i]));
for (int i = 0; i < 16; i++)
positions.push_back(string(BenchmarkPositions[i]));
- ofstream timingFile;
- if (!timFile.empty())
- {
- timingFile.open(timFile.c_str(), ios::out | ios::app);
- if (!timingFile.is_open())
- {
- cerr << "Unable to open timing file " << timFile << endl;
- Application::exit_with_failure();
- }
- }
-
vector<string>::iterator it;
int cnt = 1;
int64_t totalNodes = 0;
vector<string>::iterator it;
int cnt = 1;
int64_t totalNodes = 0;
for (it = positions.begin(); it != positions.end(); ++it, ++cnt)
{
for (it = positions.begin(); it != positions.end(); ++it, ++cnt)
{
- Move moves[1] = {MOVE_NONE};
- int dummy[2] = {0, 0};
+ Move moves[1] = { MOVE_NONE };
+ int dummy[2] = { 0, 0 };
Position pos(*it, 0);
cerr << "\nBench position: " << cnt << '/' << positions.size() << endl << endl;
if (limitType == "perft")
Position pos(*it, 0);
cerr << "\nBench position: " << cnt << '/' << positions.size() << endl << endl;
if (limitType == "perft")
<< "\nNodes searched : " << totalNodes
<< "\nNodes/second : " << (int)(totalNodes/(cnt/1000.0)) << endl << endl;
<< "\nNodes searched : " << totalNodes
<< "\nNodes/second : " << (int)(totalNodes/(cnt/1000.0)) << endl << endl;
- if (!timFile.empty())
- {
- timingFile << cnt << endl << endl;
- timingFile.close();
- }
-
// Under MS Visual C++ debug window always unconditionally closes
// when program exits, this is bad because we want to read results before.
#if (defined(WINDOWS) || defined(WIN32) || defined(WIN64))
cerr << "Press any key to exit" << endl;
// Under MS Visual C++ debug window always unconditionally closes
// when program exits, this is bad because we want to read results before.
#if (defined(WINDOWS) || defined(WIN32) || defined(WIN64))
cerr << "Press any key to exit" << endl;
}
else // Process command line arguments
{
}
else // Process command line arguments
{
- if (string(argv[1]) != "bench" || argc < 4 || argc > 8)
+ if (string(argv[1]) != "bench" || argc < 4 || argc > 7)
cout << "Usage: stockfish bench <hash size> <threads> "
cout << "Usage: stockfish bench <hash size> <threads> "
- << "[time = 60s] [fen positions file = default] "
- << "[time, depth, perft or node limited = time] "
- << "[timing file name = none]" << endl;
+ << "[limit = 12] [fen positions file = default] "
+ << "[depth, time, perft or node limited = depth]" << endl;
- string time = argc > 4 ? argv[4] : "60";
- string fen = argc > 5 ? argv[5] : "default";
- string lim = argc > 6 ? argv[6] : "time";
- string tim = argc > 7 ? argv[7] : "";
- benchmark(string(argv[2]) + " " + string(argv[3]) + " " + time + " " + fen + " " + lim + " " + tim);
+ string val = argc > 4 ? argv[4] : "12";
+ string fen = argc > 5 ? argv[5] : "default";
+ string lim = argc > 6 ? argv[6] : "depth";
+ benchmark(string(argv[2]) + " " + string(argv[3]) + " " + val + " " + fen + " " + lim);