All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
progress_perf.cc
Go to the documentation of this file.
1 /* progress_perf.cc
2  */
5 #include "osl/record/csaString.h"
6 #include "osl/record/csaRecord.h"
7 #include "osl/misc/perfmon.h"
8 
9 #include <iostream>
10 #include <fstream>
11 
12 using namespace osl;
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 void finish();
23 
24 int main(int argc, char **argv)
25 {
26  const char *program_name = argv[0];
27  bool error_flag = false;
28 
29  extern char *optarg;
30  extern int optind;
31  char c;
32  while ((c = getopt(argc, argv, "s:vh")) != EOF)
33  {
34  switch(c)
35  {
36  case 's': skip_first = atoi(optarg);
37  break;
38  default: error_flag = true;
39  }
40  }
41  argc -= optind;
42  argv += optind;
43 
44  if (error_flag || (argc < 1))
45  usage(program_name);
46 
47  try
48  {
49  for (int i=0; i<argc; ++i)
50  {
51  run(argv[i]);
52  }
53  finish();
54  }
55  catch (std::exception& e)
56  {
57  std::cerr << e.what() << "\n";
58  return 1;
59  }
60  catch (...)
61  {
62  throw;
63  }
64 }
65 
66 unsigned long long total_cycles=0;
67 unsigned long long total_cycles_naive=0;
68 unsigned long long positions = 0;
69 void run(const char *filename)
70 {
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  progress::Effect5x3 progress(state);
77  while (true)
78  {
79  if (i >= moves.size())
80  break;
81  const Move move = moves[i++];
82  state.makeMove(move);
83  if (i >= skip_first) {
84  misc::PerfMon clock;
85  progress.update(state, move);
86  total_cycles += clock.stop();
87  ++positions;
88  }
89  }
90 }
91 
92 void finish()
93 {
94  std::cerr << "p " << total_cycles << " / " << positions << " = "
95  << total_cycles/(double)positions << "\n";
96 }
97 
98 /* ------------------------------------------------------------------------- */
99 // ;;; Local Variables:
100 // ;;; mode:c++
101 // ;;; c-basic-offset:2
102 // ;;; End: