+
+/// 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[]) {
+
+ std::vector<Move> searchMoves(1, MOVE_NONE);
+ vector<string> fenList;
+ Search::LimitsType limits;
+ int64_t totalNodes;
+ int time;
+
+ // 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"].set_value(ttSize);
+ Options["Threads"].set_value(threads);
+ Options["OwnBook"].set_value("false");
+
+ // Search should be limited by nodes, time or depth ?
+ if (valType == "nodes")
+ limits.maxNodes = atoi(valStr.c_str());
+ else if (valType == "time")
+ limits.maxTime = 1000 * atoi(valStr.c_str()); // maxTime is in ms
+ else
+ limits.maxDepth = atoi(valStr.c_str());
+
+ // Do we need to load positions from a given FEN file?
+ if (fenFile != "default")
+ {
+ string fen;
+ ifstream f(fenFile.c_str());
+
+ if (!f.is_open())
+ {
+ cerr << "Unable to open file " << fenFile << endl;
+ exit(EXIT_FAILURE);
+ }
+
+ while (getline(f, fen))
+ if (!fen.empty())
+ fenList.push_back(fen);
+
+ f.close();