1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-29 16:23:09 +00:00

Reformat benchmark interface

Prepare to following patches, still no functional
change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2008-09-18 09:54:44 +01:00
parent 2f5012a3eb
commit f1e245850f
3 changed files with 45 additions and 29 deletions

View 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;
std::string ttSize, threads, fileName;
std::istringstream csVal(commandLine);
std::istringstream csStr(commandLine);
int val, time;
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);
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);
}
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 >> 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);
}
}

View 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)

View 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