+
+/// benchmark() runs a simple benchmark by letting Stockfish analyze a set
+/// of positions for a given limit each. There are five parameters; the
+/// transposition table size, the number of search threads that should
+/// be used, the limit value spent for each position (optional, default is
+/// depth 12), an optional file name where to look for positions in fen
+/// format (defaults are the positions defined above) and the type of the
+/// limit value: depth (default), time in secs or number of nodes.
+
+void benchmark(int argc, char* argv[]) {
+
+ vector<string> fens;
+ LimitsType limits;
+ int time;
+ int64_t nodes = 0;
+
+ // Assign default values to missing arguments
+ string ttSize = argc > 2 ? argv[2] : "128";
+ string threads = argc > 3 ? argv[3] : "1";
+ string valStr = argc > 4 ? argv[4] : "12";
+ string fenFile = argc > 5 ? argv[5] : "default";
+ string valType = argc > 6 ? argv[6] : "depth";
+
+ Options["Hash"] = ttSize;
+ Options["Threads"] = threads;
+ Options["OwnBook"] = false;
+
+ if (valType == "time")
+ limits.maxTime = 1000 * atoi(valStr.c_str()); // maxTime is in ms
+
+ else if (valType == "nodes")
+ limits.maxNodes = atoi(valStr.c_str());
+
+ else
+ limits.maxDepth = atoi(valStr.c_str());
+
+ if (fenFile != "default")
+ {
+ string fen;
+ ifstream file(fenFile.c_str());
+
+ if (!file.is_open())
+ {
+ cerr << "Unable to open file " << fenFile << endl;
+ exit(EXIT_FAILURE);
+ }
+
+ while (getline(file, fen))
+ if (!fen.empty())
+ fens.push_back(fen);
+
+ file.close();