Cambridge SMT System
data.stats.hpp
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use these files except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License.
12 
13 // Copyright 2012 - Gonzalo Iglesias, Adrià de Gispert, William Byrne
14 
15 #ifndef STATS_HPP
16 #define STATS_HPP
17 
23 namespace ucam {
24 namespace fsttools {
25 
28  unordered_map<std::string, std::vector<timeb> > time1;
30  unordered_map<std::string, std::vector<timeb> > time2;
31 
33  inline void setTimeStart ( const std::string& key ) {
34  timeb t;
35  time1[key].push_back ( t );
36  ftime ( &time1[key][time1[key].size() - 1] );
37  };
39  inline void setTimeEnd ( const std::string& key ) {
40  timeb t;
41  ftime ( &t );
42  time2[key].push_back ( t );
43  };
53  void write ( std::ostream &o ) {
54  for ( unordered_map<std::string, std::vector<timeb> >::iterator itx =
55  time2.begin(); itx != time2.end(); itx++ ) {
56  USER_CHECK ( time1[itx->first].size() == itx->second.size(),
57  "Mismatch with SpeedStats (each setTimeStart needs a setTimeEnd" );
58  o << std::setw ( 30 ) << setiosflags ( std::ios::right ) << itx->first << ":";
59  int64 fst_time = 0;
60  for ( unsigned k = 0; k < itx->second.size() - 1 ; ++k ) {
61  fst_time += ( itx->second[k].time - time1[itx->first][k].time ) * 1000;
62  fst_time += itx->second[k].millitm - time1[itx->first][k].millitm;
63  }
64  int64 last_time = ( itx->second[itx->second.size() - 1].time -
65  time1[itx->first][itx->second.size() - 1].time ) * 1000
66  + itx->second[itx->second.size() - 1].millitm -
67  time1[itx->first][itx->second.size() - 1].millitm;
68  fst_time += last_time;
69  o << std::setw ( 10 ) << last_time;
70  o << std::setw ( 10 ) << fst_time ;
71  o << " (" << itx->second.size() << " times )" << endl;
72  }
73  }
74 
75 };
76 
88 struct StatsData {
89 
91  lpcount ( 0 ),
92  numcats ( 0 ) {
93  }
94 
96  unsigned lpcount;
98  unsigned numcats;
99 
101  unordered_map<std::string, std::vector<timeb> > time1;
103  unordered_map<std::string, std::vector<timeb> > time2;
104 
106  unordered_map<unsigned, unsigned> rulecounts;
107 
109  unordered_map<unsigned, unsigned> numstates;
110  unordered_map<unsigned, unsigned> numprunedstates;
111 
113  std::string message;
114 
116  inline void setTimeStart ( const std::string& key ) {
117  timeb t;
118  time1[key].push_back ( t );
119  ftime ( &time1[key][time1[key].size() - 1] );
120  };
122  inline void setTimeEnd ( const std::string& key ) {
123  timeb t;
124  ftime ( &t );
125  time2[key].push_back ( t );
126  };
127 
138  for ( unordered_map<std::string, std::vector<timeb> >::iterator itx =
139  time2.begin(); itx != time2.end(); itx++ ) {
140  USER_CHECK ( time1[itx->first].size() == itx->second.size(),
141  "Mismatch with SpeedStats (each setTimeStart needs a setTimeEnd" );
142  o << std::setw ( 30 ) << setiosflags ( std::ios::right ) << itx->first << ":";
143  int64 fst_time = 0;
144  for ( unsigned k = 0; k < itx->second.size() - 1 ; ++k ) {
145  fst_time += ( itx->second[k].time - time1[itx->first][k].time ) * 1000;
146  fst_time += itx->second[k].millitm - time1[itx->first][k].millitm;
147  }
148  int64 last_time = ( itx->second[itx->second.size() - 1].time -
149  time1[itx->first][itx->second.size() - 1].time ) * 1000
150  + itx->second[itx->second.size() - 1].millitm -
151  time1[itx->first][itx->second.size() - 1].millitm;
152  fst_time += last_time;
153  o << std::setw ( 10 ) << last_time;
154  o << std::setw ( 10 ) << fst_time ;
155  o << " ms (" << itx->second.size() << " times )" << endl;
156  }
157  }
158 };
159 
160 }
161 } // end namespaces
162 
163 #endif
164 
Wrapper stream class that writes to pipes, text files or gzipped files.
Definition: szfstream.hpp:200
unordered_map< unsigned, unsigned > numprunedstates
Definition: data.stats.hpp:110
Contains data for statistics, i.e. allows timing actions and methods called during execution...
Definition: data.stats.hpp:88
unordered_map< std::string, std::vector< timeb > > time1
Stores absolute time for a key prior to executing function.
Definition: data.stats.hpp:101
unordered_map< std::string, std::vector< timeb > > time2
Stores absolute time for a key after executing function.
Definition: data.stats.hpp:30
void setTimeEnd(const std::string &key)
Store absolute timing value right after an execution.
Definition: data.stats.hpp:39
unordered_map< unsigned, unsigned > rulecounts
cyk rule counts
Definition: data.stats.hpp:106
std::string message
Any other general stuff appended here – to be printed in stats file.
Definition: data.stats.hpp:113
unordered_map< std::string, std::vector< timeb > > time2
Stores absolute time for a key after executing function.
Definition: data.stats.hpp:103
void setTimeStart(const std::string &key)
Store absolute timing value last thing, just before executing.
Definition: data.stats.hpp:116
unsigned lpcount
local pruning
Definition: data.stats.hpp:96
long long int64
void setTimeEnd(const std::string &key)
Store absolute timing value right after an execution.
Definition: data.stats.hpp:122
unordered_map< std::string, std::vector< timeb > > time1
Stores absolute time for a key prior to executing function.
Definition: data.stats.hpp:28
#define USER_CHECK(exp, comment)
Tests whether exp is true. If not, comment is printed and program ends.
void setTimeStart(const std::string &key)
Store absolute timing value last thing, just before executing.
Definition: data.stats.hpp:33
unsigned numcats
number of syntactic categories.
Definition: data.stats.hpp:98
unordered_map< unsigned, unsigned > numstates
number of states for full and pruned lattices through the cyk grid
Definition: data.stats.hpp:109
void write(std::ostream &o)
Dumps time measurements as a list of pairs key1:time1 key2:time2 ... Each key is expected to be seman...
Definition: data.stats.hpp:53
Definition: bleu.hpp:14
void write(ucam::util::oszfstream &o)
Dumps time measurements as a list of pairs key1:time1 key2:time2 ... Each key is expected to be seman...
Definition: data.stats.hpp:137