@@ -379,46 +379,53 @@ struct benchmarker {
379379 printf (" %s%-13s: %8.4f ns per block (%6.2f%%) - %8.4f ns per byte - %8.4f ns per structural - %8.3f GB/s\n " ,
380380 prefix,
381381 " Speed" ,
382- stage.elapsed_ns () / stats->blocks , // per block
383- 100.0 * stage.elapsed_sec () / all_stages.elapsed_sec (), // %
384- stage.elapsed_ns () / stats->bytes , // per byte
385- stage.elapsed_ns () / stats->structurals , // per structural
386- (json.size () / 1000000000.0 ) / stage.elapsed_sec () // GB/s
382+ stage.elapsed_ns () / static_cast < double >( stats->blocks ) , // per block
383+ percent ( stage.elapsed_sec (), all_stages.elapsed_sec () ), // %
384+ stage.elapsed_ns () / static_cast < double >( stats->bytes ) , // per byte
385+ stage.elapsed_ns () / static_cast < double >( stats->structurals ) , // per structural
386+ (static_cast < double >( json.size () ) / 1000000000.0 ) / stage.elapsed_sec () // GB/s
387387 );
388388
389389 if (collector.has_events ()) {
390390 printf (" %s%-13s: %8.4f per block (%6.2f%%) - %8.4f per byte - %8.4f per structural - %8.3f GHz est. frequency\n " ,
391391 prefix,
392392 " Cycles" ,
393- stage.cycles () / stats->blocks ,
394- 100.0 * stage.cycles () / all_stages.cycles (),
395- stage.cycles () / stats->bytes ,
396- stage.cycles () / stats->structurals ,
393+ stage.cycles () / static_cast < double >( stats->blocks ) ,
394+ percent ( stage.cycles (), all_stages.cycles () ),
395+ stage.cycles () / static_cast < double >( stats->bytes ) ,
396+ stage.cycles () / static_cast < double >( stats->structurals ) ,
397397 (stage.cycles () / stage.elapsed_sec ()) / 1000000000.0
398398 );
399399 printf (" %s%-13s: %8.4f per block (%6.2f%%) - %8.4f per byte - %8.4f per structural - %8.3f per cycle\n " ,
400400 prefix,
401401 " Instructions" ,
402- stage.instructions () / stats->blocks ,
403- 100.0 * stage.instructions () / all_stages.instructions (),
404- stage.instructions () / stats->bytes ,
405- stage.instructions () / stats->structurals ,
406- stage.instructions () / stage.cycles ()
402+ stage.instructions () / static_cast < double >( stats->blocks ) ,
403+ percent ( stage.instructions (), all_stages.instructions () ),
404+ stage.instructions () / static_cast < double >( stats->bytes ) ,
405+ stage.instructions () / static_cast < double >( stats->structurals ) ,
406+ stage.instructions () / static_cast < double >( stage.cycles () )
407407 );
408408
409409 // NOTE: removed cycles/miss because it is a somewhat misleading stat
410410 printf (" %s%-13s: %7.0f branch misses (%6.2f%%) - %.0f cache misses (%6.2f%%) - %.2f cache references\n " ,
411411 prefix,
412412 " Misses" ,
413413 stage.branch_misses (),
414- 100.0 * stage.branch_misses () / all_stages.branch_misses (),
414+ percent ( stage.branch_misses (), all_stages.branch_misses () ),
415415 stage.cache_misses (),
416- 100.0 * stage.cache_misses () / all_stages.cache_misses (),
416+ percent ( stage.cache_misses (), all_stages.cache_misses () ),
417417 stage.cache_references ()
418418 );
419419 }
420420 }
421421
422+ static double percent (size_t a, size_t b) {
423+ return 100.0 * static_cast <double >(a) / static_cast <double >(b);
424+ }
425+ static double percent (double a, double b) {
426+ return 100.0 * a / b;
427+ }
428+
422429 void print (bool tabbed_output, size_t iterations) const {
423430 if (tabbed_output) {
424431 char * filename_copy = (char *)malloc (strlen (filename)+1 );
@@ -432,14 +439,14 @@ struct benchmarker {
432439 base[strlen (base)-5 ] = ' \0 ' ;
433440 }
434441
435- double gb = json.size () / 1000000000.0 ;
442+ double gb = static_cast < double >( json.size () ) / 1000000000.0 ;
436443 if (collector.has_events ()) {
437444 printf (" \" %s\"\t %f\t %f\t %f\t %f\t %f\t %f\t %f\n " ,
438445 base,
439- allocate_stage.best .cycles () / json.size (),
440- stage1.best .cycles () / json.size (),
441- stage2.best .cycles () / json.size (),
442- all_stages.best .cycles () / json.size (),
446+ allocate_stage.best .cycles () / static_cast < double >( json.size () ),
447+ stage1.best .cycles () / static_cast < double >( json.size () ),
448+ stage2.best .cycles () / static_cast < double >( json.size () ),
449+ all_stages.best .cycles () / static_cast < double >( json.size () ),
443450 gb / all_stages.best .elapsed_sec (),
444451 gb / stage1.best .elapsed_sec (),
445452 gb / stage2.best .elapsed_sec ());
@@ -455,22 +462,22 @@ struct benchmarker {
455462 printf (" \n " );
456463 printf (" %s\n " , filename);
457464 printf (" %s\n " , string (strlen (filename), ' =' ).c_str ());
458- printf (" %9zu blocks - %10zu bytes - %5zu structurals (%5.1f %%)\n " , stats->bytes / BYTES_PER_BLOCK, stats->bytes , stats->structurals , 100.0 * stats->structurals / stats->bytes );
465+ printf (" %9zu blocks - %10zu bytes - %5zu structurals (%5.1f %%)\n " , stats->bytes / BYTES_PER_BLOCK, stats->bytes , stats->structurals , percent ( stats->structurals , stats->bytes ) );
459466 if (stats) {
460467 printf (" special blocks with: utf8 %9zu (%5.1f %%) - escape %9zu (%5.1f %%) - 0 structurals %9zu (%5.1f %%) - 1+ structurals %9zu (%5.1f %%) - 8+ structurals %9zu (%5.1f %%) - 16+ structurals %9zu (%5.1f %%)\n " ,
461- stats->blocks_with_utf8 , 100.0 * stats->blocks_with_utf8 / stats->blocks ,
462- stats->blocks_with_escapes , 100.0 * stats->blocks_with_escapes / stats->blocks ,
463- stats->blocks_with_0_structurals , 100.0 * stats->blocks_with_0_structurals / stats->blocks ,
464- stats->blocks_with_1_structural , 100.0 * stats->blocks_with_1_structural / stats->blocks ,
465- stats->blocks_with_8_structurals , 100.0 * stats->blocks_with_8_structurals / stats->blocks ,
466- stats->blocks_with_16_structurals , 100.0 * stats->blocks_with_16_structurals / stats->blocks );
468+ stats->blocks_with_utf8 , percent ( stats->blocks_with_utf8 , stats->blocks ) ,
469+ stats->blocks_with_escapes , percent ( stats->blocks_with_escapes , stats->blocks ) ,
470+ stats->blocks_with_0_structurals , percent ( stats->blocks_with_0_structurals , stats->blocks ) ,
471+ stats->blocks_with_1_structural , percent ( stats->blocks_with_1_structural , stats->blocks ) ,
472+ stats->blocks_with_8_structurals , percent ( stats->blocks_with_8_structurals , stats->blocks ) ,
473+ stats->blocks_with_16_structurals , percent ( stats->blocks_with_16_structurals , stats->blocks ) );
467474 printf (" special block flips: utf8 %9zu (%5.1f %%) - escape %9zu (%5.1f %%) - 0 structurals %9zu (%5.1f %%) - 1+ structurals %9zu (%5.1f %%) - 8+ structurals %9zu (%5.1f %%) - 16+ structurals %9zu (%5.1f %%)\n " ,
468- stats->blocks_with_utf8_flipped , 100.0 * stats->blocks_with_utf8_flipped / stats->blocks ,
469- stats->blocks_with_escapes_flipped , 100.0 * stats->blocks_with_escapes_flipped / stats->blocks ,
470- stats->blocks_with_0_structurals_flipped , 100.0 * stats->blocks_with_0_structurals_flipped / stats->blocks ,
471- stats->blocks_with_1_structural_flipped , 100.0 * stats->blocks_with_1_structural_flipped / stats->blocks ,
472- stats->blocks_with_8_structurals_flipped , 100.0 * stats->blocks_with_8_structurals_flipped / stats->blocks ,
473- stats->blocks_with_16_structurals_flipped , 100.0 * stats->blocks_with_16_structurals_flipped / stats->blocks );
475+ stats->blocks_with_utf8_flipped , percent ( stats->blocks_with_utf8_flipped , stats->blocks ) ,
476+ stats->blocks_with_escapes_flipped , percent ( stats->blocks_with_escapes_flipped , stats->blocks ) ,
477+ stats->blocks_with_0_structurals_flipped , percent ( stats->blocks_with_0_structurals_flipped , stats->blocks ) ,
478+ stats->blocks_with_1_structural_flipped , percent ( stats->blocks_with_1_structural_flipped , stats->blocks ) ,
479+ stats->blocks_with_8_structurals_flipped , percent ( stats->blocks_with_8_structurals_flipped , stats->blocks ) ,
480+ stats->blocks_with_16_structurals_flipped , percent ( stats->blocks_with_16_structurals_flipped , stats->blocks ) );
474481 }
475482 printf (" \n " );
476483 printf (" All Stages\n " );
@@ -497,7 +504,7 @@ struct benchmarker {
497504 freqmin, freqmax, freqall);
498505 }
499506 }
500- printf (" \n %.1f documents parsed per second\n " , iterations/ loop.best .elapsed_sec ());
507+ printf (" \n %.1f documents parsed per second\n " , static_cast < double >( iterations)/ static_cast < double >( loop.best .elapsed_sec () ));
501508 }
502509 }
503510};
0 commit comments