]> git.sesse.net Git - stockfish/commitdiff
Let benchmark to default to depth 12
authorMarco Costalba <mcostalba@gmail.com>
Mon, 8 Nov 2010 10:08:01 +0000 (11:08 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Mon, 8 Nov 2010 12:53:44 +0000 (13:53 +0100)
And also simplify a lot the code.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/benchmark.cpp
src/main.cpp

index e2f7c5a296dbf50dd306e6c501e01ebd03e3137f..a4d2939fd8cf1fc1a50c27a692b371bcd35706f8 100644 (file)
@@ -35,7 +35,7 @@ using namespace std;
 //// Variables
 ////
 
 //// Variables
 ////
 
-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 - -",
@@ -69,53 +69,35 @@ const string BenchmarkPositions[] = {
 
 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")
       maxDepth = val;
       maxDepth = val;
+  else if (limitType == "time")
+      secsPerPos = val * 1000;
   else
       maxNodes = val;
 
   else
       maxNodes = val;
 
-  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;
@@ -130,17 +112,6 @@ void benchmark(const string& commandLine) {
       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;
@@ -148,8 +119,8 @@ void benchmark(const string& commandLine) {
 
   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")
@@ -170,16 +141,10 @@ void benchmark(const string& commandLine) {
        << "\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;
-  cin >> fileName;
+  cin >> ttSize;
   #endif
 }
   #endif
 }
index 372e8abc58e990442d62a32c218c5f9a03a1b577..78a91aff4d09e2a97976efca99ee20861b2ec33a 100644 (file)
@@ -71,18 +71,16 @@ int main(int argc, char *argv[]) {
   }
   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;
       else
       {
       else
       {
-          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);
       }
   }
 
       }
   }