@@ -77,15 +77,6 @@ int main(int argc, char *argv[]) {
7777 return EXIT_FAILURE;
7878 }
7979 if (verbose) cout << " [verbose] loaded " << filename << " (" << p.size () << " bytes)" << endl;
80- ParsedJson pj;
81- bool allocok = pj.allocateCapacity (p.size ());
82- if (!allocok) {
83- std::cerr << " failed to allocate memory" << std::endl;
84- return EXIT_FAILURE;
85- }
86-
87- if (verbose) cout << " [verbose] allocated memory for parsed JSON " << endl;
88-
8980#if defined(DEBUG)
9081 const u32 iterations = 1 ;
9182#else
@@ -108,16 +99,35 @@ int main(int argc, char *argv[]) {
10899 LinuxEvents<PERF_TYPE_HARDWARE> unified (evts);
109100 vector<u64 > results;
110101 results.resize (evts.size ());
111- unsigned long cy1 = 0 , cy2 = 0 , cy3 = 0 ;
112- unsigned long cl1 = 0 , cl2 = 0 , cl3 = 0 ;
113- unsigned long mis1 = 0 , mis2 = 0 , mis3 = 0 ;
114- unsigned long cref1 = 0 , cref2 = 0 , cref3 = 0 ;
115- unsigned long cmis1 = 0 , cmis2 = 0 , cmis3 = 0 ;
102+ unsigned long cy0 = 0 , cy1 = 0 , cy2 = 0 , cy3 = 0 ;
103+ unsigned long cl0 = 0 , cl1 = 0 , cl2 = 0 , cl3 = 0 ;
104+ unsigned long mis0 = 0 , mis1 = 0 , mis2 = 0 , mis3 = 0 ;
105+ unsigned long cref0 = 0 , cref1 = 0 , cref2 = 0 , cref3 = 0 ;
106+ unsigned long cmis0 = 0 , cmis1 = 0 , cmis2 = 0 , cmis3 = 0 ;
116107#endif
117108 bool isok = true ;
118109
119110 for (u32 i = 0 ; i < iterations; i++) {
120111 if (verbose) cout << " [verbose] iteration # " << i << endl;
112+ #ifndef SQUASH_COUNTERS
113+ unified.start ();
114+ #endif
115+ ParsedJson pj;
116+ bool allocok = pj.allocateCapacity (p.size ());
117+ if (!allocok) {
118+ std::cerr << " failed to allocate memory" << std::endl;
119+ return EXIT_FAILURE;
120+ }
121+ #ifndef SQUASH_COUNTERS
122+ unified.end (results);
123+ cy0 += results[0 ];
124+ cl0 += results[1 ];
125+ mis0 += results[2 ];
126+ cref0 += results[3 ];
127+ cmis0 += results[4 ];
128+ #endif
129+ if (verbose) cout << " [verbose] allocated memory for parsed JSON " << endl;
130+
121131 auto start = std::chrono::steady_clock::now ();
122132#ifndef SQUASH_COUNTERS
123133 unified.start ();
@@ -169,13 +179,21 @@ int main(int argc, char *argv[]) {
169179 std::chrono::duration<double > secs = end - start;
170180 res[i] = secs.count ();
171181 }
172-
182+ ParsedJson pj = build_parsed_json (p); // do the parsing again to get the stats
183+ if ( ! pj.isValid () ) {
184+ std::cerr << " could not parse again? " << std::endl;
185+ return EXIT_FAILURE;
186+ }
173187#ifndef SQUASH_COUNTERS
174188 printf (" number of bytes %ld number of structural chars %u ratio %.3f\n " ,
175189 p.size (), pj.n_structural_indexes ,
176190 (double )pj.n_structural_indexes / p.size ());
177- unsigned long total = cy1 + cy2 + cy3;
178-
191+ unsigned long total = cy0 + cy1 + cy2 + cy3;
192+ printf (
193+ " mem alloc instructions: %10lu cycles: %10lu (%.2f %%) ins/cycles: %.2f mis. branches: %10lu (cycles/mis.branch %.2f) cache accesses: %10lu (failure %10lu)\n " ,
194+ cl0 / iterations, cy0 / iterations, 100 . * cy0 / total, (double )cl0 / cy0, mis0/iterations, (double )cy0/mis0, cref1 / iterations, cmis0 / iterations);
195+ printf (" mem alloc runs at %.2f cycles per input byte.\n " ,
196+ (double )cy0 / (iterations * p.size ()));
179197 printf (
180198 " stage 1 instructions: %10lu cycles: %10lu (%.2f %%) ins/cycles: %.2f mis. branches: %10lu (cycles/mis.branch %.2f) cache accesses: %10lu (failure %10lu)\n " ,
181199 cl1 / iterations, cy1 / iterations, 100 . * cy1 / total, (double )cl1 / cy1, mis1/iterations, (double )cy1/mis1, cref1 / iterations, cmis1 / iterations);
0 commit comments