repositories
/
poolifier.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
3fc1a3e
)
Some benchmarking improvements
author
aardizio
<alessandroardizio94@gmail.com>
Tue, 21 Jan 2020 23:38:14 +0000
(
00:38
+0100)
committer
aardizio
<alessandroardizio94@gmail.com>
Tue, 21 Jan 2020 23:38:14 +0000
(
00:38
+0100)
benchmarks/myBench.js
patch
|
blob
|
blame
|
history
diff --git
a/benchmarks/myBench.js
b/benchmarks/myBench.js
index 6ea0abfed5e92b28fc5a5e1e833111fe6a77ad37..45f11b296fbaa96408bdfd6caa923f257226eda7 100644
(file)
--- a/
benchmarks/myBench.js
+++ b/
benchmarks/myBench.js
@@
-7,7
+7,7
@@
const size = 10
// pools
const externalPool = new Pool({ max: size })
const fixedPool = new FixedThreadPool(size, './yourWorker.js', { maxTasks: 10000 })
// pools
const externalPool = new Pool({ max: size })
const fixedPool = new FixedThreadPool(size, './yourWorker.js', { maxTasks: 10000 })
-const dynamicPool = new DynamicThreadPool(size
, size * 2
, './yourWorker.js', { maxTasks: 10000 })
+const dynamicPool = new DynamicThreadPool(size
/ 2, 50
, './yourWorker.js', { maxTasks: 10000 })
// data
const workerData = { proof: 'ok' }
// data
const workerData = { proof: 'ok' }
@@
-16,28
+16,30
@@
const workerData = { proof: 'ok' }
async function fixedTest () {
let executions = 0
const time = Date.now()
async function fixedTest () {
let executions = 0
const time = Date.now()
- for (let i = 0; i < tasks; i++) {
- await fixedPool.execute(workerData)
- executions++
+ for (let i = 0; i <= tasks; i++) {
+ fixedPool.execute(workerData).then(res => {
+ executions++
+ if (executions === tasks) console.log(`Fixed pool take ${Date.now() - time} to work on ${executions} tasks`)
+ })
}
}
- console.log(`Fixed pool take ${Date.now() - time} to work on ${executions} tasks`)
}
async function dynamicTest () {
let executions = 0
const time = Date.now()
}
async function dynamicTest () {
let executions = 0
const time = Date.now()
- for (let i = 0; i < tasks; i++) {
- await dynamicPool.execute(workerData)
- executions++
+ for (let i = 0; i <= tasks; i++) {
+ dynamicPool.execute(workerData).then(res => {
+ executions++
+ if (executions === tasks) console.log(`Dynamic pool take ${Date.now() - time} to work on ${executions} tasks`)
+ })
}
}
- console.log(`Dynamic pool take ${Date.now() - time} to work on ${executions} tasks`)
}
async function externalPoolTest () {
let executions = 0
const time = Date.now()
}
async function externalPoolTest () {
let executions = 0
const time = Date.now()
- for (let i = 0; i < tasks; i++) {
-
await
new Promise((resolve, reject) => {
+ for (let i = 0; i <
=
tasks; i++) {
+ new Promise((resolve, reject) => {
externalPool.acquire('./externalWorker.js', { workerData: workerData }, (err, worker) => {
if (err) {
return reject(err)
externalPool.acquire('./externalWorker.js', { workerData: workerData }, (err, worker) => {
if (err) {
return reject(err)
@@
-48,15
+50,16
@@
async function externalPoolTest () {
resolve(res)
})
})
resolve(res)
})
})
+ }).then(res => {
+ if (tasks === executions) console.log(`External pool take ${Date.now() - time} to work on ${executions} tasks`)
})
}
})
}
- console.log(`External pool take ${Date.now() - time} to work on ${executions} tasks`)
}
async function test () {
}
async function test () {
-
await
fixedTest()
-
await
dynamicTest()
-
await
externalPoolTest()
+ fixedTest()
+ dynamicTest()
+ externalPoolTest()
}
test()
}
test()