Skip to content
This repository
Browse code

Teach Benchmark to read positions from a file

This comes handy to test the engine on different
sets of positions, not only the 15 default ones.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
  • Loading branch information...
commit 925f97f4e761136c8a845d98f55303137fade589 1 parent f1e2458
Marco Costalba authored

Showing 1 changed file with 38 additions and 13 deletions. Show diff stats Hide diff stats

  1. +38 13 src/benchmark.cpp
51 src/benchmark.cpp
@@ -20,7 +20,9 @@
20 20 ////
21 21 //// Includes
22 22 ////
  23 +#include <fstream>
23 24 #include <sstream>
  25 +#include <vector>
24 26
25 27 #include "benchmark.h"
26 28 #include "search.h"
@@ -55,19 +57,20 @@ const std::string BenchmarkPositions[15] = {
55 57 //// Functions
56 58 ////
57 59
58   -/// benchmark() runs a simple benchmark by letting Glaurung analyze 15
59   -/// positions for 60 seconds each. There are two parameters; the
60   -/// transposition table size and the number of search threads that should
61   -/// be used. The analysis is written to a file named bench.txt.
  60 +/// benchmark() runs a simple benchmark by letting Glaurung analyze a set
  61 +/// of positions for a given time each. There are four parameters; the
  62 +/// transposition table size, the number of search threads that should
  63 +/// be used, the time in seconds spent for each position (optional, default
  64 +/// is 60) and an optional file name where to look for positions in fen
  65 +/// format (default are the BenchmarkPositions defined above).
  66 +/// The analysis is written to a file named bench.txt.
62 67
63 68 void benchmark(const std::string& commandLine) {
64 69
65   - Position pos;
66   - Move moves[1] = {MOVE_NONE};
67   - std::string ttSize, threads, fileName;
68 70 std::istringstream csVal(commandLine);
69 71 std::istringstream csStr(commandLine);
70   - int val, time;
  72 + std::string ttSize, threads, fileName;
  73 + int val, secsPerPos;
71 74
72 75 csStr >> ttSize;
73 76 csVal >> val;
@@ -90,15 +93,37 @@ void benchmark(const std::string& commandLine) {
90 93 set_option_value("Use Search Log", "true");
91 94 set_option_value("Search Log Filename", "bench.txt");
92 95
93   - csVal >> time; // In seconds
  96 + csVal >> secsPerPos;
94 97 csVal >> fileName;
  98 +
  99 + std::vector<std::string> positions;
95 100
96 101 if (fileName != "default")
97   - exit(0);
  102 + {
  103 + std::ifstream fenFile(fileName.c_str());
  104 + if (!fenFile.is_open())
  105 + {
  106 + std::cerr << "Unable to open positions file " << fileName
  107 + << std::endl;
  108 + exit(EXIT_FAILURE);
  109 + }
  110 + std::string pos;
  111 + while (fenFile.good())
  112 + {
  113 + std::getline(fenFile, pos);
  114 + if (!pos.empty())
  115 + positions.push_back(pos);
  116 + }
  117 + fenFile.close();
  118 + } else
  119 + for (int i = 0; i < 15; i++)
  120 + positions.push_back(std::string(BenchmarkPositions[i]));
98 121
99   - for (int i = 0; i < 15; i++)
  122 + std::vector<std::string>::iterator it;
  123 + for (it = positions.begin(); it != positions.end(); ++it)
100 124 {
101   - pos.from_fen(BenchmarkPositions[i]);
102   - think(pos, true, false, 0, 0, 0, 0, 0, time * 1000, moves);
  125 + Move moves[1] = {MOVE_NONE};
  126 + Position pos(*it);
  127 + think(pos, true, false, 0, 0, 0, 0, 0, secsPerPos * 1000, moves);
103 128 }
104 129 }

0 comments on commit 925f97f

Please sign in to comment.
Something went wrong with that request. Please try again.