+
+/// 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(const Position& current, istream& is) {
+
+ string token;
+ Search::LimitsType limits;
+ vector<string> fens;
+
+ // Assign default values to missing arguments
+ string ttSize = (is >> token) ? token : "32";
+ string threads = (is >> token) ? token : "1";
+ string limit = (is >> token) ? token : "12";
+ string fenFile = (is >> token) ? token : "default";
+ string limitType = (is >> token) ? token : "depth";
+
+ Options["Hash"] = ttSize;
+ Options["Threads"] = threads;
+ TT.clear();
+
+ if (limitType == "time")
+ limits.movetime = 1000 * atoi(limit.c_str()); // movetime is in ms
+
+ else if (limitType == "nodes")
+ limits.nodes = atoi(limit.c_str());
+
+ else if (limitType == "mate")
+ limits.mate = atoi(limit.c_str());
+
+ else
+ limits.depth = atoi(limit.c_str());
+
+ if (fenFile == "default")
+ fens.assign(Defaults, Defaults + 16);
+
+ else if (fenFile == "current")
+ fens.push_back(current.fen());
+
+ else
+ {
+ string fen;
+ ifstream file(fenFile.c_str());
+
+ if (!file.is_open())
+ {
+ cerr << "Unable to open file " << fenFile << endl;
+ return;
+ }
+
+ while (getline(file, fen))
+ if (!fen.empty())
+ fens.push_back(fen);
+
+ file.close();