All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
see-perf.cc
Go to the documentation of this file.
1 #include "osl/eval/see.h"
2 #include "osl/eval/pieceEval.h"
3 #include "osl/effect_util/pin.h"
4 #include "osl/record/csaRecord.h"
8 #include "osl/stat/average.h"
9 #include "osl/misc/perfmon.h"
10 
11 #include <boost/format.hpp>
12 #include <string>
13 #include <iostream>
14 #include <iomanip>
15 #include <cmath>
16 #include <cstdio>
17 using namespace osl;
18 
24 void usage(const char *prog)
25 {
26  using namespace std;
27  cerr << "Usage: " << prog << " [-v] [-f skip] [-o] csafiles\n"
28  << endl;
29  exit(1);
30 }
31 
32 size_t first_skip = 0;
33 bool verbose = false;
34 bool old = false;
35 
37 
38 void test_file(const char *filename);
39 
40 int main(int argc, char **argv)
41 {
42  const char *program_name = argv[0];
43  bool error_flag = false;
44  extern char *optarg;
45  extern int optind;
46 
47  char c;
48  while ((c = getopt(argc, argv, "f:ovh")) != EOF)
49  {
50  switch(c)
51  {
52  case 'f': first_skip = atoi(optarg);
53  break;
54  case 'v': verbose = true;
55  break;
56  case 'o': old = true;
57  break;
58  default: error_flag = true;
59  }
60  }
61  argc -= optind;
62  argv += optind;
63 
64  if (error_flag || (argc < 1))
65  usage(program_name);
66 
67  for (int i=0; i<argc; ++i)
68  {
69  if (i % 128 == 0)
70  std::cerr << '.';
71  test_file(argv[i]);
72  }
73 
74  std::cout << "average cycles/position " << cycles.getAverage() << "\n"
75  << "average cycles/position/move " << cycles_per_move.getAverage()
76  << "\n";
77 }
78 
79 /* ------------------------------------------------------------------------- */
80 
81 size_t num_positions = 0;
82 void test_position(const NumEffectState& state)
83 {
84  MoveVector moves;
85  LegalMoves::generate(state, moves);
86  const PieceMask my_pin = effect_util::Pin::make(state, state.turn());
87  const PieceMask op_pin = effect_util::Pin::make(state, alt(state.turn()));
88 
89  misc::PerfMon clock;
90  for (size_t i=0; i<moves.size(); ++i) {
91  if (old)
92  PieceEval::computeDiffAfterMoveForRP(state, moves[i]);
93  else
94  See::see(state, moves[i], my_pin, op_pin);
95  }
96  const size_t consumed = clock.stop();
97  cycles.add(consumed);
98  cycles_per_move.add(consumed/moves.size());
99  ++num_positions;
100 }
101 
102 void test_file(const char *filename)
103 {
104  Record rec;
105  try {
106  rec = CsaFile(filename).getRecord();
107  }
108  catch (CsaIOError& e) {
109  std::cerr << "skip " << filename <<"\n";
110  std::cerr << e.what() << "\n";
111  return;
112  }
113  catch (...) {
114  throw;
115  }
116 
117  NumEffectState state(rec.getInitialState());
118  const osl::stl::vector<osl::Move> moves=rec.getMoves();
119 
120  for (size_t i=0; i<moves.size(); ++i) {
121  const Move move = moves[i];
122  assert(state.isValidMove(move));
123  if (i >= first_skip) {
124  test_position(state);
125  }
126  state.makeMove(move);
127  }
128 }
129 
130 /* ------------------------------------------------------------------------- */
131 // ;;; Local Variables:
132 // ;;; mode:c++
133 // ;;; c-basic-offset:2
134 // ;;; End: