@@ -97,7 +97,7 @@ int main(int argc, char *argv[]) {
9797#endif
9898 std::vector<double > res;
9999 res.resize (iterations);
100-
100+ printf ( " number of iterations %u \n " , iterations);
101101#if !defined(__linux__)
102102#define SQUASH_COUNTERS
103103 if (justdata) {
@@ -122,38 +122,29 @@ int main(int argc, char *argv[]) {
122122 unsigned long cmis0 = 0 , cmis1 = 0 , cmis2 = 0 ;
123123#endif
124124 bool isok = true ;
125-
125+ # ifndef SQUASH_COUNTERS
126126 for (uint32_t i = 0 ; i < iterations; i++) {
127127 if (verbose) {
128128 std::cout << " [verbose] iteration # " << i << std::endl;
129129 }
130- #ifndef SQUASH_COUNTERS
131130 unified.start ();
132- #endif
133131 ParsedJson pj;
134132 bool allocok = pj.allocateCapacity (p.size ());
135133 if (!allocok) {
136134 std::cerr << " failed to allocate memory" << std::endl;
137135 return EXIT_FAILURE ;
138136 }
139- #ifndef SQUASH_COUNTERS
140137 unified.end (results);
141138 cy0 += results[0 ];
142139 cl0 += results[1 ];
143140 mis0 += results[2 ];
144141 cref0 += results[3 ];
145142 cmis0 += results[4 ];
146- #endif
147143 if (verbose) {
148144 std::cout << " [verbose] allocated memory for parsed JSON " << std::endl;
149- }
150-
151- auto start = std::chrono::steady_clock::now ();
152- #ifndef SQUASH_COUNTERS
145+ }
153146 unified.start ();
154- #endif
155147 isok = find_structural_bits (p.data (), p.size (), pj);
156- #ifndef SQUASH_COUNTERS
157148 unified.end (results);
158149 cy1 += results[0 ];
159150 cl1 += results[1 ];
@@ -165,10 +156,7 @@ int main(int argc, char *argv[]) {
165156 break ;
166157 }
167158 unified.start ();
168- #endif
169-
170159 isok = isok && (simdjson::SUCCESS == unified_machine (p.data (), p.size (), pj));
171- #ifndef SQUASH_COUNTERS
172160 unified.end (results);
173161 cy2 += results[0 ];
174162 cl2 += results[1 ];
@@ -179,12 +167,34 @@ int main(int argc, char *argv[]) {
179167 std::cout << " Failed during stage 2" << std::endl;
180168 break ;
181169 }
170+ }
182171#endif
172+ // we do it again, this time just measuring the elapsed time
173+ for (uint32_t i = 0 ; i < iterations; i++) {
174+ if (verbose) {
175+ std::cout << " [verbose] iteration # " << i << std::endl;
176+ }
177+ ParsedJson pj;
178+ bool allocok = pj.allocateCapacity (p.size ());
179+ if (!allocok) {
180+ std::cerr << " failed to allocate memory" << std::endl;
181+ return EXIT_FAILURE ;
182+ }
183+ if (verbose) {
184+ std::cout << " [verbose] allocated memory for parsed JSON " << std::endl;
185+ }
183186
187+ auto start = std::chrono::steady_clock::now ();
188+ isok = find_structural_bits (p.data (), p.size (), pj);
189+ isok = isok && (simdjson::SUCCESS == unified_machine (p.data (), p.size (), pj));
184190 auto end = std::chrono::steady_clock::now ();
185191 std::chrono::duration<double > secs = end - start;
186192 res[i] = secs.count ();
187- }
193+ if (! isok) {
194+ std::cerr << " Could not parse. " << std::endl;
195+ return EXIT_FAILURE ;
196+ }
197+ }
188198 ParsedJson pj = build_parsed_json (p); // do the parsing again to get the stats
189199 if (!pj.isValid ()) {
190200 std::cerr << " Could not parse. " << std::endl;
0 commit comments