From: Marco Costalba Date: Thu, 18 Sep 2008 08:54:44 +0000 (+0100) Subject: Reformat benchmark interface X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=f1e245850f55578bd55cb9448a832233dc229a86 Reformat benchmark interface Prepare to following patches, still no functional change. Signed-off-by: Marco Costalba --- diff --git a/src/benchmark.cpp b/src/benchmark.cpp index 4bd1ac84..05829173 100644 --- a/src/benchmark.cpp +++ b/src/benchmark.cpp @@ -20,6 +20,7 @@ //// //// Includes //// +#include #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); } - } diff --git a/src/benchmark.h b/src/benchmark.h index 9ca68f83..7903a546 100644 --- a/src/benchmark.h +++ b/src/benchmark.h @@ -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) diff --git a/src/main.cpp b/src/main.cpp index 49c66c0d..bd4958d9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 " << std::endl; + if (argc >= 2 && string(argv[1]) == "bench") + { + if (argc < 4 || argc > 6) + { + std::cout << "Usage: glaurung bench " + << "[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