-
Notifications
You must be signed in to change notification settings - Fork 5
/
benchmarking.js
109 lines (103 loc) · 3.24 KB
/
benchmarking.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
const Benchmark = require("benchmark");
const ora = require("ora");
const inquirer = require("inquirer");
const createCsvWriter = require("csv-writer").createObjectCsvWriter;
const spinner = ora("Starting Benchmarking");
const suite = new Benchmark.Suite({
onStart: () => {
spinner.start("Starting Benchmarking");
},
onComplete: () => {
spinner.stop();
}
});
const csvWriter = createCsvWriter({
append: true,
path: "benchmark.csv",
header: [
{ id: "range", title: "Range" },
{ id: "thread", title: "Thread" },
{ id: "DS", title: "DS" },
{ id: "meanTime", title: "Mean-Time" },
{ id: "noOfTest", title: "No.-Of-Tests" }
]
});
const sharedBufferPrime = require("./sharedArrayBuffer");
const arrayBuffer = require("./arrayBuffer");
const array = require("./array");
const normalSieve = require("./normalSieve");
const data = [];
const run = async () => {
const { primeRange } = await inquirer.prompt([
{
type: "input",
name: "primeRange",
message: "Benchmark till ?",
default: 100
}
]);
suite
.add(String(primeRange) + " sharedArrayBuffer", {
defer: true,
fn: async deferred => {
await sharedBufferPrime(primeRange);
deferred.resolve();
}
})
.add(String(primeRange) + " arrayBuffer", {
defer: true,
fn: async deferred => {
await arrayBuffer(primeRange);
deferred.resolve();
}
})
.add(String(primeRange) + " array", {
defer: true,
fn: async deferred => {
await array(primeRange);
deferred.resolve();
}
})
.add(String(primeRange) + " normalSieve", {
defer: true,
fn: async deferred => {
await normalSieve(primeRange);
deferred.resolve();
}
})
// add listeners
.on("cycle", function(event) {
spinner.stopAndPersist({
text: `${event.target.name} Cycle finished`,
symbol: "⌛"
});
if(event.target.name.split(" ")[1] == "normalSieve"){
var label = "main";
}else{
var label = "worker"
}
data.push({
range: event.target.name.split(" ")[0],
thread: label,
DS: event.target.name.split(" ")[1],
meanTime: event.target.stats.mean,
noOfTest: event.target.stats.sample.length
});
console.log(`Mean Exec time : ${event.target.stats.mean} seconds`);
console.log(
"Number of tests : " + event.target.stats.sample.length
);
spinner.start();
})
.on("complete", function() {
// console.log('Fastest is ' + this.filter('fastest').map('name'));
csvWriter
.writeRecords(data)
.then(() =>
console.log("The CSV file was written successfully")
);
})
// run async
.run({ async: true });
};
run();