X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fbenchmark.cpp;h=766b769873528d09d22720296a2e10aad89321e1;hp=02037689df0b770b7c07a0d1b347c0de11f362d4;hb=8fabd69d4a70380daa547362ed83be1091b86414;hpb=27619830d428693b4871ce58770705b30ba84c99 diff --git a/src/benchmark.cpp b/src/benchmark.cpp index 02037689..766b7698 100644 --- a/src/benchmark.cpp +++ b/src/benchmark.cpp @@ -1,7 +1,7 @@ /* Stockfish, a UCI chess playing engine derived from Glaurung 2.1 Copyright (C) 2004-2008 Tord Romstad (Glaurung author) - Copyright (C) 2008-2009 Marco Costalba + Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad Stockfish is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -72,7 +72,7 @@ void benchmark(const string& 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; @@ -84,9 +84,9 @@ void benchmark(const string& commandLine) { } csStr >> threads; csVal >> val; - if (val < 1 || val > THREAD_MAX) + if (val < 1 || val > MAX_THREADS) { - cerr << "The number of threads must be between 1 and " << THREAD_MAX << endl; + cerr << "The number of threads must be between 1 and " << MAX_THREADS << endl; Application::exit_with_failure(); } set_option_value("Hash", ttSize); @@ -98,12 +98,13 @@ void benchmark(const string& commandLine) { csVal >> val; csVal >> fileName; csVal >> limitType; + csVal >> timFile; secsPerPos = maxDepth = maxNodes = 0; if (limitType == "time") secsPerPos = val * 1000; - else if (limitType == "depth") + else if (limitType == "depth" || limitType == "perft") maxDepth = val; else maxNodes = val; @@ -130,21 +131,51 @@ void benchmark(const string& commandLine) { 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::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); - cout << "\nProcessing position " << cnt << '/' << positions.size() << endl << endl; - if (!think(pos, true, false, 0, dummy, dummy, 0, maxDepth, maxNodes, secsPerPos, moves)) + cerr << "\nBench position: " << cnt << '/' << positions.size() << endl << endl; + if (limitType == "perft") + totalNodes += perft(pos, maxDepth * OnePly); + else if (!think(pos, false, false, 0, dummy, dummy, 0, maxDepth, maxNodes, secsPerPos, moves)) break; totalNodes += nodes_searched(); } - cout << "\nProcessing time (ms) " << get_system_time() - startTime - << "\nNodes searched " << totalNodes << "\nPress any key to exit" << endl; + + cnt = get_system_time() - startTime; + 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)) + cerr << "Press any key to exit" << endl; cin >> fileName; + #endif }