@@ -551,14 +551,23 @@ class Benchmark {
551
551
return `
552
552
let __benchmark = new Benchmark(${ this . iterations } );
553
553
let results = [];
554
+ let benchmarkName = "${ this . name } ";
555
+
554
556
for (let i = 0; i < ${ this . iterations } ; i++) {
555
557
if (__benchmark.prepareForNextIteration)
556
558
__benchmark.prepareForNextIteration();
557
559
558
560
${ this . preIterationCode }
561
+
562
+ const iterationMarkLabel = benchmarkName + "-iteration-" + i;
563
+ const iterationStartMark = performance.mark(iterationMarkLabel);
564
+
559
565
let start = performance.now();
560
566
__benchmark.runIteration();
561
567
let end = performance.now();
568
+
569
+ performanceMeasure(iterationMarkLabel, iterationStartMark);
570
+
562
571
${ this . postIterationCode }
563
572
564
573
results.push(Math.max(1, end - start));
@@ -619,7 +628,24 @@ class Benchmark {
619
628
assert ( false , "Should not reach here in CLI" ) ;
620
629
} ;
621
630
622
- addScript ( `const isInBrowser = ${ isInBrowser } ;` ) ;
631
+ addScript ( `
632
+ const isInBrowser = ${ isInBrowser } ;
633
+ const isD8 = ${ isD8 } ;
634
+ if (typeof performance.mark === 'undefined') {
635
+ performance.mark = function() {};
636
+ }
637
+ if (typeof performance.measure === 'undefined') {
638
+ performance.measure = function() {};
639
+ }
640
+ function performanceMeasure(name, mark) {
641
+ // D8 does not implement the official web API.
642
+ // Also the performance.mark polyfill returns an undefined mark.
643
+ if (isD8 || typeof mark === "undefined")
644
+ performance.measure(name, mark);
645
+ else
646
+ performance.measure(name, mark.name);
647
+ }
648
+ ` ) ;
623
649
624
650
if ( ! ! this . plan . deterministicRandom ) {
625
651
addScript ( `
@@ -683,7 +709,7 @@ class Benchmark {
683
709
}
684
710
addScript ( this . runnerCode ) ;
685
711
686
- this . startTime = new Date ( ) ;
712
+ this . startTime = performance . now ( ) ;
687
713
688
714
if ( RAMification )
689
715
resetMemoryPeak ( ) ;
@@ -698,7 +724,7 @@ class Benchmark {
698
724
}
699
725
const results = await promise ;
700
726
701
- this . endTime = new Date ( ) ;
727
+ this . endTime = performance . now ( ) ;
702
728
703
729
if ( RAMification ) {
704
730
const memoryFootprint = MemoryFootprint ( ) ;
@@ -997,12 +1023,22 @@ class AsyncBenchmark extends DefaultBenchmark {
997
1023
async function doRun() {
998
1024
let __benchmark = new Benchmark();
999
1025
let results = [];
1026
+ let benchmarkName = "${ this . name } ";
1027
+
1000
1028
for (let i = 0; i < ${ this . iterations } ; i++) {
1001
1029
${ this . preIterationCode }
1030
+
1031
+ const iterationMarkLabel = benchmarkName + "-iteration-" + i;
1032
+ const iterationStartMark = performance.mark(iterationMarkLabel);
1033
+
1002
1034
let start = performance.now();
1003
1035
await __benchmark.runIteration();
1004
1036
let end = performance.now();
1037
+
1038
+ performanceMeasure(iterationMarkLabel, iterationStartMark);
1039
+
1005
1040
${ this . postIterationCode }
1041
+
1006
1042
results.push(Math.max(1, end - start));
1007
1043
}
1008
1044
if (__benchmark.validate)
0 commit comments