forked from marijaselakovic/JavaScriptIssuesStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsexecutorWarmUpAndTest.js
34 lines (31 loc) · 1.1 KB
/
jsexecutorWarmUpAndTest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Author: Michael Pradel
(function () {
var testCasePath = process.argv[2];
var warmUpRepetitions = process.argv[3];
var measurementRepetitions = process.argv[4];
var testCase = require('./' + testCasePath);
var init = testCase.init();
var ss = require('simple-statistics');
// warm up
for (var i = 0; i < warmUpRepetitions; i++) {
var setupTestResult = testCase.setupTest(init);
testCase.test(init, setupTestResult);
}
// measurement
var measuredTimes = [];
for (var i = 0; i < measurementRepetitions; i++) {
var setupTestResult = testCase.setupTest(init);
var start = process.hrtime();
testCase.test(init, setupTestResult);
var stop = process.hrtime(start);
var time = stop[0] * 1e9 + stop[1];
measuredTimes.push(time);
}
// print mean time to console
/* var sum = measuredTimes.reduce(function (previous, current) {
return previous + current;
}, 0);
var mean = sum / measuredTimes.length;*/
var mean=Math.round(parseFloat(ss.mean(measuredTimes)));
console.log('mean:'+mean);
})();