]> git.sesse.net Git - stockfish/commitdiff
Add support for saving timing file during benchmark
authorMarco Costalba <mcostalba@gmail.com>
Sat, 4 Jul 2009 09:32:51 +0000 (10:32 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 4 Jul 2009 09:32:51 +0000 (10:32 +0100)
Add a new argument to bench to specify the name of the
file where timing information will be saved for each
benchmark session.

This argument is optional, if not specified file will
not be created.

Original patch by Heinz van Saanen

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

index 590299d91439b981974fcd8c19647f909ae85072..b90d3fcb151f6172f7ea22a2b81d766778acd050 100644 (file)
@@ -72,7 +72,7 @@ void benchmark(const string& commandLine) {
 
   istringstream csVal(commandLine);
   istringstream csStr(commandLine);
 
   istringstream csVal(commandLine);
   istringstream csStr(commandLine);
-  string ttSize, threads, fileName, limitType;
+  string ttSize, threads, fileName, limitType, timFile;
   int val, secsPerPos, maxDepth, maxNodes;
 
   csStr >> ttSize;
   int val, secsPerPos, maxDepth, maxNodes;
 
   csStr >> ttSize;
@@ -98,6 +98,7 @@ void benchmark(const string& commandLine) {
   csVal >> val;
   csVal >> fileName;
   csVal >> limitType;
   csVal >> val;
   csVal >> fileName;
   csVal >> limitType;
+  csVal >> timFile;
 
   secsPerPos = maxDepth = maxNodes = 0;
 
 
   secsPerPos = maxDepth = maxNodes = 0;
 
@@ -130,30 +131,49 @@ 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]));
 
-  int startTime = get_system_time();
+  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;
+  int startTime = get_system_time();
+
   for (it = positions.begin(); it != positions.end(); ++it, ++cnt)
   {
       Move moves[1] = {MOVE_NONE};
       int dummy[2] = {0, 0};
       Position pos(*it);
   for (it = positions.begin(); it != positions.end(); ++it, ++cnt)
   {
       Move moves[1] = {MOVE_NONE};
       int dummy[2] = {0, 0};
       Position pos(*it);
-      cout << "\nProcessing position " << cnt << '/' << positions.size() << endl << endl;
+      cerr << "\nBench position: " << cnt << '/' << positions.size() << endl << endl;
       if (!think(pos, true, false, 0, dummy, dummy, 0, maxDepth, maxNodes, secsPerPos, moves))
           break;
       totalNodes += nodes_searched();
   }
       if (!think(pos, true, false, 0, dummy, dummy, 0, maxDepth, maxNodes, secsPerPos, moves))
           break;
       totalNodes += nodes_searched();
   }
+
   cnt = get_system_time() - startTime;
   cnt = get_system_time() - startTime;
-  cout << "\nProcessing time (ms) " << cnt
-       << "\nNodes searched " << totalNodes
-       << "\nNodes/second " << (int)(totalNodes/(cnt/1000.0))
-       << endl;
+  cerr << "==============================="
+       << "\nTotal time (ms) : " << cnt
+       << "\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))
 
   // 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))
-  cout << "Press any key to exit" << endl;
+  cerr << "Press any key to exit" << endl;
   cin >> fileName;
   #endif
 }
   cin >> fileName;
   #endif
 }
index 94ee076be147cf5513950a57fe6f89eb2b183bd8..c57b1f414ca23fdf38385787a373b80631a6acb4 100644 (file)
@@ -60,16 +60,18 @@ int main(int argc, char *argv[]) {
   // Process command line arguments if any
   if (argc > 1)
   {
   // Process command line arguments if any
   if (argc > 1)
   {
-      if (string(argv[1]) != "bench" || argc < 4 || argc > 7)
+      if (string(argv[1]) != "bench" || argc < 4 || argc > 8)
           cout << "Usage: stockfish bench <hash size> <threads> "
                << "[time = 60s] [fen positions file = default] "
           cout << "Usage: stockfish bench <hash size> <threads> "
                << "[time = 60s] [fen positions file = default] "
-               << "[time, depth or node limited = time]" << endl;
+               << "[time, depth or node limited = time] "
+               << "[timing file name = none]" << endl;
       else
       {
           string time = argc > 4 ? argv[4] : "60";
           string fen = argc > 5 ? argv[5] : "default";
           string lim = argc > 6 ? argv[6] : "time";
       else
       {
           string time = argc > 4 ? argv[4] : "60";
           string fen = argc > 5 ? argv[5] : "default";
           string lim = argc > 6 ? argv[6] : "time";
-          benchmark(string(argv[2]) + " " + string(argv[3]) + " " + time + " " + fen + " " + lim);
+          string tim = argc > 7 ? argv[7] : "";
+          benchmark(string(argv[2]) + " " + string(argv[3]) + " " + time + " " + fen + " " + lim + " " + tim);
       }
       return 0;
   }
       }
       return 0;
   }