@@ -555,14 +555,23 @@ class Benchmark {
555
555
return `
556
556
let __benchmark = new Benchmark(${ this . iterations } );
557
557
let results = [];
558
+ let benchmarkName = "${ this . name } ";
559
+
558
560
for (let i = 0; i < ${ this . iterations } ; i++) {
559
561
if (__benchmark.prepareForNextIteration)
560
562
__benchmark.prepareForNextIteration();
561
563
562
564
${ this . preIterationCode }
565
+
566
+ const iterationMarkLabel = benchmarkName + "-iteration-" + i;
567
+ const iterationStartMark = performance.mark(iterationMarkLabel);
568
+
563
569
let start = performance.now();
564
570
__benchmark.runIteration();
565
571
let end = performance.now();
572
+
573
+ performanceMeasure(iterationMarkLabel, iterationStartMark);
574
+
566
575
${ this . postIterationCode }
567
576
568
577
results.push(Math.max(1, end - start));
@@ -623,7 +632,24 @@ class Benchmark {
623
632
assert ( false , "Should not reach here in CLI" ) ;
624
633
} ;
625
634
626
- addScript ( `const isInBrowser = ${ isInBrowser } ;` ) ;
635
+ addScript ( `
636
+ const isInBrowser = ${ isInBrowser } ;
637
+ const isD8 = ${ isD8 } ;
638
+ if (typeof performance.mark === 'undefined') {
639
+ performance.mark = function() {};
640
+ }
641
+ if (typeof performance.measure === 'undefined') {
642
+ performance.measure = function() {};
643
+ }
644
+ function performanceMeasure(name, mark) {
645
+ // D8 does not implement the official web API.
646
+ // Also the performance.mark polyfill returns an undefined mark.
647
+ if (isD8 || typeof mark === "undefined")
648
+ performance.measure(name, mark);
649
+ else
650
+ performance.measure(name, mark.name);
651
+ }
652
+ ` ) ;
627
653
628
654
if ( ! ! this . plan . deterministicRandom ) {
629
655
addScript ( `
@@ -687,7 +713,7 @@ class Benchmark {
687
713
}
688
714
addScript ( this . runnerCode ) ;
689
715
690
- this . startTime = new Date ( ) ;
716
+ this . startTime = performance . now ( ) ;
691
717
692
718
if ( RAMification )
693
719
resetMemoryPeak ( ) ;
@@ -702,7 +728,7 @@ class Benchmark {
702
728
}
703
729
const results = await promise ;
704
730
705
- this . endTime = new Date ( ) ;
731
+ this . endTime = performance . now ( ) ;
706
732
707
733
if ( RAMification ) {
708
734
const memoryFootprint = MemoryFootprint ( ) ;
@@ -1007,12 +1033,22 @@ class AsyncBenchmark extends DefaultBenchmark {
1007
1033
async function doRun() {
1008
1034
let __benchmark = new Benchmark();
1009
1035
let results = [];
1036
+ let benchmarkName = "${ this . name } ";
1037
+
1010
1038
for (let i = 0; i < ${ this . iterations } ; i++) {
1011
1039
${ this . preIterationCode }
1040
+
1041
+ const iterationMarkLabel = benchmarkName + "-iteration-" + i;
1042
+ const iterationStartMark = performance.mark(iterationMarkLabel);
1043
+
1012
1044
let start = performance.now();
1013
1045
await __benchmark.runIteration();
1014
1046
let end = performance.now();
1047
+
1048
+ performanceMeasure(iterationMarkLabel, iterationStartMark);
1049
+
1015
1050
${ this . postIterationCode }
1051
+
1016
1052
results.push(Math.max(1, end - start));
1017
1053
}
1018
1054
if (__benchmark.validate)
0 commit comments