]> git.sesse.net Git - stockfish/blobdiff - src/benchmark.cpp
Rewrite async I/O
[stockfish] / src / benchmark.cpp
index 4b3e417eb734b5c6c41068328c5ee0f9ff6d19a8..551c341b1043df21dfc56d0a0c0cdecdae42a589 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "position.h"
 #include "search.h"
+#include "thread.h"
 #include "ucioption.h"
 
 using namespace std;
@@ -49,25 +50,19 @@ static const string Defaults[] = {
 
 
 /// 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
-/// be used, the limit value spent for each position (optional, default
-/// is ply 12), an optional file name where to look for positions in fen
-/// format (default are the BenchmarkPositions defined above) and the type
-/// of the limit value: depth (default), time in secs or number of nodes.
-/// The analysis is written to a file named bench.txt.
+/// 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> fenList;
-  SearchLimits limits;
   int64_t totalNodes;
   int time;
 
-  // Load default positions
-  for (int i = 0; !Defaults[i].empty(); i++)
-      fenList.push_back(Defaults[i]);
-
   // Assign default values to missing arguments
   string ttSize  = argc > 2 ? argv[2] : "128";
   string threads = argc > 3 ? argv[3] : "1";
@@ -81,58 +76,58 @@ void benchmark(int argc, char* argv[]) {
 
   // Search should be limited by nodes, time or depth ?
   if (valType == "nodes")
-      limits.maxNodes = atoi(valStr.c_str());
+      Limits.maxNodes = atoi(valStr.c_str());
   else if (valType == "time")
-      limits.maxTime = 1000 * atoi(valStr.c_str()); // maxTime is in ms
+      Limits.maxTime = 1000 * atoi(valStr.c_str()); // maxTime is in ms
   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")
   {
       string fen;
       ifstream f(fenFile.c_str());
 
-      if (f.is_open())
-      {
-          fenList.clear();
-
-          while (getline(f, fen))
-              if (!fen.empty())
-                  fenList.push_back(fen);
-
-          f.close();
-      }
-      else
+      if (!f.is_open())
       {
-          cerr << "Unable to open FEN file " << fenFile << endl;
+          cerr << "Unable to open file " << fenFile << endl;
           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 !
   totalNodes = 0;
   time = get_system_time();
+  SearchMoves.push_back(MOVE_NONE);
 
   for (size_t i = 0; i < fenList.size(); i++)
   {
-      Move moves[] = { MOVE_NONE };
       Position pos(fenList[i], false, 0);
+      RootPosition = &pos;
 
       cerr << "\nBench position: " << i + 1 << '/' << fenList.size() << endl;
 
       if (valType == "perft")
       {
-          int64_t cnt = perft(pos, limits.maxDepth * ONE_PLY);
-          totalNodes += cnt;
+          int64_t cnt = perft(pos, Limits.maxDepth * ONE_PLY);
 
-          cerr << "\nPerft " << limits.maxDepth << " nodes counted: " << cnt << endl;
+          cerr << "\nPerft " << Limits.maxDepth
+               << " nodes counted: " << cnt << endl;
+
+          totalNodes += cnt;
       }
       else
       {
-          if (!think(pos, limits, moves))
-              break;
-
+          Threads.start_thinking(false);
           totalNodes += pos.nodes_searched();
       }
   }