]> git.sesse.net Git - stockfish/commitdiff
Reformat benchmark interface
authorMarco Costalba <mcostalba@gmail.com>
Thu, 18 Sep 2008 08:54:44 +0000 (09:54 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Thu, 18 Sep 2008 10:26:39 +0000 (12:26 +0200)
Prepare to following patches, still no functional
change.

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

index 4bd1ac84d5525bac358fb1d74be0fa1156a81c30..058291732567b10cf71e2a1a29e5be0aa304fe0c 100644 (file)
@@ -20,6 +20,7 @@
 ////
 //// Includes
 ////
+#include <sstream>
 
 #include "benchmark.h"
 #include "search.h"
@@ -59,33 +60,45 @@ const std::string BenchmarkPositions[15] = {
 /// transposition table size and the number of search threads that should
 /// be used.  The analysis is written to a file named bench.txt.
 
-void benchmark(const std::string &ttSize, const std::string &threads) {
+void benchmark(const std::string& commandLine) {
+
   Position pos;
   Move moves[1] = {MOVE_NONE};
-  int i;
-
-  i = atoi(ttSize.c_str());
-  if(i < 4 || i > 1024) {
-    std::cerr << "The hash table size must be between 4 and 1024" << std::endl;
-    exit(EXIT_FAILURE);
-  }
+  std::string ttSize, threads, fileName;
+  std::istringstream csVal(commandLine);
+  std::istringstream csStr(commandLine);
+  int val, time;
 
-  i = atoi(threads.c_str());
-  if(i < 1 || i > THREAD_MAX) {
-    std::cerr << "The number of threads must be between 1 and " << THREAD_MAX
-              << std::endl;
-    exit(EXIT_FAILURE);
+  csStr >> ttSize;
+  csVal >> val;
+  if (val < 4 || val > 1024)
+  {
+      std::cerr << "The hash table size must be between 4 and 1024" << std::endl;
+      exit(EXIT_FAILURE);
   }
-  
+  csStr >> threads;
+  csVal >> val;
+  if (val < 1 || val > THREAD_MAX)
+  {
+      std::cerr << "The number of threads must be between 1 and " << THREAD_MAX
+                << std::endl;
+      exit(EXIT_FAILURE);
+  }  
   set_option_value("Hash", ttSize);
   set_option_value("Threads", threads);
   set_option_value("OwnBook", "false");
   set_option_value("Use Search Log", "true");
   set_option_value("Search Log Filename", "bench.txt");
 
-  for(i = 0; i < 15; i++) {
-    pos.from_fen(BenchmarkPositions[i]);
-    think(pos, true, false, 0, 0, 0, 0, 0, 60000, moves);
+  csVal >> time; // In seconds
+  csVal >> fileName;
+  
+  if (fileName != "default")
+      exit(0);
+
+  for (int i = 0; i < 15; i++)
+  {
+      pos.from_fen(BenchmarkPositions[i]);
+      think(pos, true, false, 0, 0, 0, 0, 0, time * 1000, moves);
   }
-    
 }
index 9ca68f83abdbd8e5b54b2982cf6395b586c7d8d4..7903a5467ff9b6a814b5f830454da735d1eea01a 100644 (file)
@@ -31,7 +31,6 @@
 //// Prototypes
 ////
 
-extern void benchmark(const std::string &ttSize, const std::string &threads);
-
+extern void benchmark(const std::string& commandLine);
 
 #endif // !defined(BENCHMARK_H_INCLUDED)
index 49c66c0da69384e761034607a9548936a9ae9fe7..bd4958d92043fca396a00a01a3f4ffe3658a10e9 100644 (file)
@@ -39,6 +39,7 @@
 #include "uci.h"
 #include "ucioption.h"
 
+using std::string;
 
 //// 
 //// Functions
@@ -67,20 +68,23 @@ int main(int argc, char *argv[]) {
   init_threads();
 
   // Make random number generation less deterministic, for book moves
-  int i = abs(get_system_time() % 10000);
-  for(int j = 0; j < i; j++)
-    genrand_int32();
+  for (int i = abs(get_system_time() % 10000); i > 0; i--)
+      genrand_int32();
 
   // Process command line arguments
-  if(argc >= 2) {
-    if(std::string(argv[1]) == "bench") {
-      if(argc != 4) {
-        std::cout << "Usage: glaurung bench <hash> <threads>" << std::endl;
+  if (argc >= 2 && string(argv[1]) == "bench")
+  {
+      if (argc < 4 || argc > 6)
+      {
+        std::cout << "Usage: glaurung bench <hash size> <threads> "
+                  << "[time = 60s] [fen positions file = default]"
+                  << std::endl;
         exit(0);
       }
-      benchmark(std::string(argv[2]), std::string(argv[3]));
+      string time = argc > 4 ? argv[4] : "60";
+      string fen = argc > 5 ? argv[5] : "default";
+      benchmark(string(argv[2]) + " " + string(argv[3]) + " " + time + " " + fen);
       return 0;
-    }
   }
 
   // Print copyright notice