All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
pin_perf.cc
Go to the documentation of this file.
1 /* pin_perf.cc
2  */
3 #include "osl/effect_util/pin.h"
4 #include "osl/record/csaString.h"
5 #include "osl/record/csaRecord.h"
6 #include "osl/misc/perfmon.h"
7 
8 #include <iostream>
9 #include <fstream>
10 
11 using namespace osl;
12 using namespace osl::effect_util;
13 
14 void usage(const char *program_name)
15 {
16  std::cerr << program_name << " csafiles\n";
17  exit(1);
18 }
19 
20 size_t skip_first = 0;
21 void run(const char *filename);
22 
23 int main(int argc, char **argv)
24 {
25  const char *program_name = argv[0];
26  bool error_flag = false;
27 
28  extern char *optarg;
29  extern int optind;
30  char c;
31  while ((c = getopt(argc, argv, "s:vh")) != EOF)
32  {
33  switch(c)
34  {
35  case 's': skip_first = atoi(optarg);
36  break;
37  default: error_flag = true;
38  }
39  }
40  argc -= optind;
41  argv += optind;
42 
43  if (error_flag || (argc < 1))
44  usage(program_name);
45 
46  try
47  {
48  for (int i=0; i<argc; ++i)
49  {
50  run(argv[i]);
51  }
52  }
53  catch (std::exception& e)
54  {
55  std::cerr << e.what() << "\n";
56  return 1;
57  }
58  catch (...)
59  {
60  throw;
61  }
62 }
63 
64 void run(const char *filename)
65 {
66  unsigned long long total_cycles=0;
67  unsigned long long total_cycles_naive=0;
68  unsigned long long total_cycles_step=0;
69  unsigned long long total_cycles_step1=0;
70  unsigned long long positions = 0;
71  Record rec=CsaFile(filename).getRecord();
72  NumEffectState state(rec.getInitialState());
73  const vector<osl::Move> moves=rec.getMoves();
74 
75  size_t i=0;
76  while (true)
77  {
78  if (i >= skip_first)
79  {
80  misc::PerfMon clock;
81  const PieceMask black_pins = Pin::make(state, BLACK);
82  const PieceMask white_pins = Pin::make(state, WHITE);
83  total_cycles += clock.stop();
84  clock.restart();
85  const PieceMask black_pins_naive = Pin::makeNaive(state, BLACK);
86  const PieceMask white_pins_naive = Pin::makeNaive(state, WHITE);
87  total_cycles_naive += clock.stop();
88  clock.restart();
89  const PieceMask black_pins_step = Pin::makeStep(state, state.kingSquare<BLACK>(),BLACK);
90  const PieceMask white_pins_step = Pin::makeStep(state, state.kingSquare<WHITE>(),WHITE);
91  total_cycles_step += clock.stop();
92  clock.restart();
93  const PieceMask black_pins_step1 = Pin::makeStep1(state, state.kingSquare<BLACK>(),BLACK);
94  const PieceMask white_pins_step1 = Pin::makeStep1(state, state.kingSquare<WHITE>(),WHITE);
95  total_cycles_step1 += clock.stop();
96  ++positions;
97  }
98  if (i >= moves.size())
99  break;
100  const Move move = moves[i++];
101  state.makeMove(move);
102  }
103  std::cerr << "p " << total_cycles << " / " << positions << " = "
104  << total_cycles/(double)positions << "\n";
105  std::cerr << "n " << total_cycles_naive << " / " << positions << " = "
106  << total_cycles_naive/(double)positions << "\n";
107  std::cerr << "n " << total_cycles_step << " / " << positions << " = "
108  << total_cycles_step/(double)positions << "\n";
109  std::cerr << "n " << total_cycles_step1 << " / " << positions << " = "
110  << total_cycles_step1/(double)positions << "\n";
111 }
112 
113 /* ------------------------------------------------------------------------- */
114 // ;;; Local Variables:
115 // ;;; mode:c++
116 // ;;; c-basic-offset:2
117 // ;;; End: