@@ -148,6 +148,8 @@ struct option_struct {
148148struct feature_benchmarker {
149149 benchmarker utf8;
150150 benchmarker utf8_miss;
151+ benchmarker escape;
152+ benchmarker escape_miss;
151153 benchmarker empty;
152154 benchmarker empty_miss;
153155 benchmarker struct7;
@@ -161,6 +163,8 @@ struct feature_benchmarker {
161163 feature_benchmarker (json_parser& parser, event_collector& collector) :
162164 utf8 (" jsonexamples/generated/utf-8.json" , parser, collector),
163165 utf8_miss (" jsonexamples/generated/utf-8-miss.json" , parser, collector),
166+ escape (" jsonexamples/generated/escape.json" , parser, collector),
167+ escape_miss (" jsonexamples/generated/escape-miss.json" , parser, collector),
164168 empty (" jsonexamples/generated/0-structurals.json" , parser, collector),
165169 empty_miss (" jsonexamples/generated/0-structurals-miss.json" , parser, collector),
166170 struct7 (" jsonexamples/generated/7-structurals.json" , parser, collector),
@@ -180,6 +184,8 @@ struct feature_benchmarker {
180184 struct7_full.run_iterations (iterations, stage1_only);
181185 utf8.run_iterations (iterations, stage1_only);
182186 utf8_miss.run_iterations (iterations, stage1_only);
187+ escape.run_iterations (iterations, stage1_only);
188+ escape_miss.run_iterations (iterations, stage1_only);
183189 empty.run_iterations (iterations, stage1_only);
184190 empty_miss.run_iterations (iterations, stage1_only);
185191 struct15.run_iterations (iterations, stage1_only);
@@ -258,12 +264,27 @@ struct feature_benchmarker {
258264 return double (utf8_miss[stage].best .branch_misses () - utf8[stage].best .branch_misses ()) / utf8_miss.stats ->blocks_with_utf8_flipped ;
259265 }
260266
267+ // Extra cost of having escapes in a block
268+ double escape_cost (BenchmarkStage stage) const {
269+ return cost_per_block (stage, escape, escape.stats ->blocks_with_escapes , struct7_full);
270+ }
271+ // Extra cost of an escape miss
272+ double escape_miss_cost (BenchmarkStage stage) const {
273+ return cost_per_block (stage, escape_miss, escape_miss.stats ->blocks_with_escapes_flipped , escape);
274+ }
275+ // Rate of escape misses per escape flip
276+ double escape_miss_rate (BenchmarkStage stage) const {
277+ if (!has_events ()) { return 1 ; }
278+ return double (escape_miss[stage].best .branch_misses () - escape[stage].best .branch_misses ()) / escape_miss.stats ->blocks_with_escapes_flipped ;
279+ }
280+
261281 double calc_expected_feature_cost (BenchmarkStage stage, const benchmarker& file) const {
262282 // Expected base ns/block (empty)
263283 json_stats& stats = *file.stats ;
264284 double expected = base_cost (stage) * stats.blocks ;
265285 expected += struct1_7_cost (stage) * stats.blocks_with_1_structural ;
266286 expected += utf8_cost (stage) * stats.blocks_with_utf8 ;
287+ expected += escape_cost (stage) * stats.blocks_with_escapes ;
267288 expected += struct8_15_cost (stage) * stats.blocks_with_8_structurals ;
268289 expected += struct16_cost (stage) * stats.blocks_with_16_structurals ;
269290 return expected / stats.blocks ;
@@ -274,6 +295,7 @@ struct feature_benchmarker {
274295 json_stats& stats = *file.stats ;
275296 double expected = struct1_7_miss_cost (stage) * stats.blocks_with_1_structural_flipped * struct1_7_miss_rate (stage);
276297 expected += utf8_miss_cost (stage) * stats.blocks_with_utf8_flipped * utf8_miss_rate (stage);
298+ expected += escape_miss_cost (stage) * stats.blocks_with_escapes_flipped * escape_miss_rate (stage);
277299 expected += struct8_15_miss_cost (stage) * stats.blocks_with_8_structurals_flipped * struct8_15_miss_rate (stage);
278300 expected += struct16_miss_cost (stage) * stats.blocks_with_16_structurals_flipped * struct16_miss_rate (stage);
279301 return expected / stats.blocks ;
@@ -283,6 +305,7 @@ struct feature_benchmarker {
283305 json_stats& stats = *file.stats ;
284306 double expected = stats.blocks_with_1_structural_flipped * struct1_7_miss_rate (stage);
285307 expected += stats.blocks_with_utf8_flipped * utf8_miss_rate (stage);
308+ expected += stats.blocks_with_escapes_flipped * escape_miss_rate (stage);
286309 expected += stats.blocks_with_8_structurals_flipped * struct8_15_miss_rate (stage);
287310 expected += stats.blocks_with_16_structurals_flipped * struct16_miss_rate (stage);
288311 return expected;
@@ -300,10 +323,12 @@ struct feature_benchmarker {
300323 printf (" | %8s " , " Base" );
301324 printf (" | %8s " , " 7 Struct" );
302325 printf (" | %8s " , " UTF-8" );
326+ printf (" | %8s " , " Escape" );
303327 printf (" | %8s " , " 15 Str." );
304328 printf (" | %8s " , " 16+ Str." );
305329 printf (" | %15s " , " 7 Struct Miss" );
306330 printf (" | %15s " , " UTF-8 Miss" );
331+ printf (" | %15s " , " Escape Miss" );
307332 printf (" | %15s " , " 15 Str. Miss" );
308333 printf (" | %15s " , " 16+ Str. Miss" );
309334 printf (" |\n " );
@@ -314,6 +339,8 @@ struct feature_benchmarker {
314339 printf (" |%.10s" , " ---------------------------------------" );
315340 printf (" |%.10s" , " ---------------------------------------" );
316341 printf (" |%.10s" , " ---------------------------------------" );
342+ printf (" |%.10s" , " ---------------------------------------" );
343+ printf (" |%.17s" , " ---------------------------------------" );
317344 printf (" |%.17s" , " ---------------------------------------" );
318345 printf (" |%.17s" , " ---------------------------------------" );
319346 printf (" |%.17s" , " ---------------------------------------" );
@@ -325,16 +352,19 @@ struct feature_benchmarker {
325352 printf (" | %8.3g " , base_cost (stage));
326353 printf (" | %8.3g " , struct1_7_cost (stage));
327354 printf (" | %8.3g " , utf8_cost (stage));
355+ printf (" | %8.3g " , escape_cost (stage));
328356 printf (" | %8.3g " , struct8_15_cost (stage));
329357 printf (" | %8.3g " , struct16_cost (stage));
330358 if (has_events ()) {
331359 printf (" | %8.3g (%3d%%) " , struct1_7_miss_cost (stage), int (struct1_7_miss_rate (stage)*100 ));
332360 printf (" | %8.3g (%3d%%) " , utf8_miss_cost (stage), int (utf8_miss_rate (stage)*100 ));
361+ printf (" | %8.3g (%3d%%) " , escape_miss_cost (stage), int (escape_miss_rate (stage)*100 ));
333362 printf (" | %8.3g (%3d%%) " , struct8_15_miss_cost (stage), int (struct8_15_miss_rate (stage)*100 ));
334363 printf (" | %8.3g (%3d%%) " , struct16_miss_cost (stage), int (struct16_miss_rate (stage)*100 ));
335364 } else {
336365 printf (" | %8.3g " , struct1_7_miss_cost (stage));
337366 printf (" | %8.3g " , utf8_miss_cost (stage));
367+ printf (" | %8.3g " , escape_miss_cost (stage));
338368 printf (" | %8.3g " , struct8_15_miss_cost (stage));
339369 printf (" | %8.3g " , struct16_miss_cost (stage));
340370 }
@@ -349,7 +379,7 @@ void print_file_effectiveness(BenchmarkStage stage, const char* filename, const
349379 uint64_t actual_misses = results[stage].best .branch_misses ();
350380 uint64_t calc_misses = uint64_t (features.calc_expected_misses (stage, results));
351381 double calc_miss_cost = features.calc_expected_miss_cost (stage, results);
352- printf (" | %-8s " , benchmark_stage_name (stage));
382+ printf (" | %-8s " , benchmark_stage_name (stage));
353383 printf (" | %-15s " , filename);
354384 printf (" | %8.3g " , features.calc_expected_feature_cost (stage, results));
355385 printf (" | %8.3g " , calc_miss_cost);
@@ -412,45 +442,47 @@ int main(int argc, char *argv[]) {
412442 features.print (options);
413443
414444 // Gauge effectiveness
415- printf (" \n " );
416- printf (" Estimated vs. Actual ns/block for real files:\n " );
417- printf (" \n " );
418- printf (" | %8s " , " Stage" );
419- printf (" | %-15s " , " File" );
420- printf (" | %11s " , " Est. (Base)" );
421- printf (" | %11s " , " Est. (Miss)" );
422- printf (" | %8s " , " Est." );
423- printf (" | %8s " , " Actual" );
424- printf (" | %8s " , " Diff" );
425- printf (" | %13s " , " Est. Misses" );
426- if (features.has_events ()) {
427- printf (" | %13s " , " Actual Misses" );
428- printf (" | %13s " , " Diff (Misses)" );
429- printf (" | %13s " , " Adjusted Miss" );
430- printf (" | %13s " , " Adjusted Diff" );
431- }
432- printf (" |\n " );
433- printf (" |%.10s" , " ---------------------------------------" );
434- printf (" |%.17s" , " ---------------------------------------" );
435- printf (" |%.13s" , " ---------------------------------------" );
436- printf (" |%.13s" , " ---------------------------------------" );
437- printf (" |%.10s" , " ---------------------------------------" );
438- printf (" |%.10s" , " ---------------------------------------" );
439- printf (" |%.10s" , " ---------------------------------------" );
440- printf (" |%.15s" , " ---------------------------------------" );
441- if (features.has_events ()) {
442- printf (" |%.15s" , " ---------------------------------------" );
443- printf (" |%.15s" , " ---------------------------------------" );
444- printf (" |%.15s" , " ---------------------------------------" );
445+ if (options.verbose ) {
446+ printf (" \n " );
447+ printf (" Effectiveness Check: Estimated vs. Actual ns/block for real files:\n " );
448+ printf (" \n " );
449+ printf (" | %8s " , " Stage" );
450+ printf (" | %-15s " , " File" );
451+ printf (" | %11s " , " Est. (Base)" );
452+ printf (" | %11s " , " Est. (Miss)" );
453+ printf (" | %8s " , " Est." );
454+ printf (" | %8s " , " Actual" );
455+ printf (" | %8s " , " Diff" );
456+ printf (" | %13s " , " Est. Misses" );
457+ if (features.has_events ()) {
458+ printf (" | %13s " , " Actual Misses" );
459+ printf (" | %13s " , " Diff (Misses)" );
460+ printf (" | %13s " , " Adjusted Miss" );
461+ printf (" | %13s " , " Adjusted Diff" );
462+ }
463+ printf (" |\n " );
464+ printf (" |%.10s" , " ---------------------------------------" );
465+ printf (" |%.17s" , " ---------------------------------------" );
466+ printf (" |%.13s" , " ---------------------------------------" );
467+ printf (" |%.13s" , " ---------------------------------------" );
468+ printf (" |%.10s" , " ---------------------------------------" );
469+ printf (" |%.10s" , " ---------------------------------------" );
470+ printf (" |%.10s" , " ---------------------------------------" );
445471 printf (" |%.15s" , " ---------------------------------------" );
446- }
447- printf (" |\n " );
472+ if (features.has_events ()) {
473+ printf (" |%.15s" , " ---------------------------------------" );
474+ printf (" |%.15s" , " ---------------------------------------" );
475+ printf (" |%.15s" , " ---------------------------------------" );
476+ printf (" |%.15s" , " ---------------------------------------" );
477+ }
478+ printf (" |\n " );
448479
449- options.each_stage ([&](auto stage) {
450- print_file_effectiveness (stage, " gsoc-2018.json" , gsoc_2018, features);
451- print_file_effectiveness (stage, " twitter.json" , twitter, features);
452- print_file_effectiveness (stage, " random.json" , random, features);
453- });
480+ options.each_stage ([&](auto stage) {
481+ print_file_effectiveness (stage, " gsoc-2018.json" , gsoc_2018, features);
482+ print_file_effectiveness (stage, " twitter.json" , twitter, features);
483+ print_file_effectiveness (stage, " random.json" , random, features);
484+ });
485+ }
454486
455487 return EXIT_SUCCESS ;
456488}
0 commit comments