X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fbenchmark.cpp;h=ee1128043f32f9b94f20f1722f2df55bc074ae5b;hp=eef27c6a5b0f2f6ae85f81f735f8fa2faac9a78f;hb=bb3427ca85bdb20b4c8af12b63f635d03c5e9146;hpb=7ac6e3b8506f54ddb8fb6560fbf238242627a141 diff --git a/src/benchmark.cpp b/src/benchmark.cpp index eef27c6a..ee112804 100644 --- a/src/benchmark.cpp +++ b/src/benchmark.cpp @@ -23,14 +23,15 @@ #include "position.h" #include "search.h" +#include "thread.h" #include "ucioption.h" using namespace std; static const string Defaults[] = { "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 - -", + "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 10", + "8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 11", "4rrk1/pp1n3p/3q2pQ/2p1pb2/2PP4/2P3N1/P2B2PP/4RRK1 b - - 7 19", "rq3rk1/ppp2ppp/1bnpb3/3N2B1/3NP3/7P/PPPQ1PP1/2KR3R w - - 7 14", "r1bq1r1k/1pp1n1pp/1p1p4/4p2Q/4Pp2/1BNP4/PPP2PPP/3R1RK1 w - - 2 14", @@ -49,25 +50,21 @@ static const string Defaults[] = { /// benchmark() runs a simple benchmark by letting Stockfish analyze a set -/// of positions for a given limit each. There are five parameters; the +/// of positions for a given limit each. There are five parameters; the /// transposition table size, the number of search threads that should -/// be used, the limit value spent for each position (optional, default -/// is ply 12), an optional file name where to look for positions in fen -/// format (default are the BenchmarkPositions defined above) and the type -/// of the limit value: depth (default), time in secs or number of nodes. -/// The analysis is written to a file named bench.txt. +/// be used, the limit value spent for each position (optional, default is +/// depth 12), an optional file name where to look for positions in fen +/// format (defaults are the positions defined above) and the type of the +/// limit value: depth (default), time in secs or number of nodes. void benchmark(int argc, char* argv[]) { + std::vector searchMoves(1, MOVE_NONE); vector fenList; - SearchLimits limits; + Search::LimitsType limits; int64_t totalNodes; int time; - // Load default positions - for (int i = 0; !Defaults[i].empty(); i++) - fenList.push_back(Defaults[i]); - // Assign default values to missing arguments string ttSize = argc > 2 ? argv[2] : "128"; string threads = argc > 3 ? argv[3] : "1"; @@ -87,28 +84,27 @@ void benchmark(int argc, char* argv[]) { else limits.maxDepth = atoi(valStr.c_str()); - // Do we need to load positions from a given FEN file ? + // Do we need to load positions from a given FEN file? if (fenFile != "default") { string fen; ifstream f(fenFile.c_str()); - if (f.is_open()) - { - fenList.clear(); - - while (getline(f, fen)) - if (!fen.empty()) - fenList.push_back(fen); - - f.close(); - } - else + if (!f.is_open()) { - cerr << "Unable to open FEN file " << fenFile << endl; + cerr << "Unable to open file " << fenFile << endl; exit(EXIT_FAILURE); } + + while (getline(f, fen)) + if (!fen.empty()) + fenList.push_back(fen); + + f.close(); } + else // Load default positions + for (int i = 0; !Defaults[i].empty(); i++) + fenList.push_back(Defaults[i]); // Ok, let's start the benchmark ! totalNodes = 0; @@ -116,24 +112,23 @@ void benchmark(int argc, char* argv[]) { for (size_t i = 0; i < fenList.size(); i++) { - Move moves[] = { MOVE_NONE }; Position pos(fenList[i], false, 0); cerr << "\nBench position: " << i + 1 << '/' << fenList.size() << endl; if (valType == "perft") { - int64_t cnt = perft(pos, limits.maxDepth * ONE_PLY); - totalNodes += cnt; + int64_t cnt = Search::perft(pos, limits.maxDepth * ONE_PLY); - cerr << "\nPerft " << limits.maxDepth << " nodes counted: " << cnt << endl; + cerr << "\nPerft " << limits.maxDepth + << " nodes counted: " << cnt << endl; + + totalNodes += cnt; } else { - if (!think(pos, limits, moves)) - break; - - totalNodes += pos.nodes_searched(); + Threads.start_thinking(pos, limits, searchMoves, false); + totalNodes += Search::RootPosition.nodes_searched(); } }