X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fbenchmark.cpp;h=7e2628b1ea77e7d82b38547bd8cdb8d0d64e751c;hp=4bd1ac84d5525bac358fb1d74be0fa1156a81c30;hb=1373a00187f9f6ee282a77a6039386c2746964b6;hpb=bb751d6c890f5c50c642366d601740366cfae8d0 diff --git a/src/benchmark.cpp b/src/benchmark.cpp index 4bd1ac84..7e2628b1 100644 --- a/src/benchmark.cpp +++ b/src/benchmark.cpp @@ -20,6 +20,9 @@ //// //// Includes //// +#include +#include +#include #include "benchmark.h" #include "search.h" @@ -54,38 +57,74 @@ const std::string BenchmarkPositions[15] = { //// Functions //// -/// benchmark() runs a simple benchmark by letting Glaurung analyze 15 -/// positions for 60 seconds each. There are two parameters; the -/// transposition table size and the number of search threads that should -/// be used. The analysis is written to a file named bench.txt. +/// benchmark() runs a simple benchmark by letting Glaurung analyze a set +/// of positions for a given time each. There are four parameters; the +/// transposition table size, the number of search threads that should +/// be used, the time in seconds spent for each position (optional, default +/// is 60) and an optional file name where to look for positions in fen +/// format (default are the BenchmarkPositions defined above). +/// The analysis is written to a file named bench.txt. -void benchmark(const std::string &ttSize, const std::string &threads) { - Position pos; - Move moves[1] = {MOVE_NONE}; - int i; +void benchmark(const std::string& commandLine) { - 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::istringstream csVal(commandLine); + std::istringstream csStr(commandLine); + std::string ttSize, threads, fileName; + int val, secsPerPos; - 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 >> secsPerPos; + csVal >> fileName; + + std::vector positions; + + if (fileName != "default") + { + std::ifstream fenFile(fileName.c_str()); + if (!fenFile.is_open()) + { + std::cerr << "Unable to open positions file " << fileName + << std::endl; + exit(EXIT_FAILURE); + } + std::string pos; + while (fenFile.good()) + { + std::getline(fenFile, pos); + if (!pos.empty()) + positions.push_back(pos); + } + fenFile.close(); + } else + for (int i = 0; i < 15; i++) + positions.push_back(std::string(BenchmarkPositions[i])); + + std::vector::iterator it; + for (it = positions.begin(); it != positions.end(); ++it) + { + Move moves[1] = {MOVE_NONE}; + int dummy[2] = {0, 0}; + Position pos(*it); + think(pos, true, false, 0, dummy, dummy, 0, 0, 0, secsPerPos * 1000, moves); } - }