Skip to content
Snippets Groups Projects
Commit e863f427 authored by Moritz Langenstein's avatar Moritz Langenstein
Browse files

(ml5717) Added seq vs parallel benchmark, pretty print results

parent b0de4136
No related branches found
No related tags found
1 merge request!67Benchmark testing
Pipeline #106771 passed
import chalk from "chalk"
import { connect } from "../src/room.js"
import MockConnection, {
......@@ -14,6 +16,21 @@ import MockConnection, {
eventListeners,
} from "../src/connection/MockConnection.js"
function printBenchmark(title, iterations, results) {
process.stdout.write(`\n ${title} (${iterations} its):\n`)
for (const title in results) {
process.stdout.write(
chalk` {yellow ⧗} {dim ${title}:} {yellow.inverse ${(
results[title] /
(1e6 * iterations)
).toFixed(3)}ms / it}\n`,
)
}
process.stdout.write(`\n`)
}
const handshake = {
uid: "tiger",
channel: "tw-ml",
......@@ -76,7 +93,7 @@ describe("drawing app mesh", () => {
)
})
it("benchmarks a single draw and erase update", () => {
it("benchmarks a single draw and erase update sequentially", () => {
const ITERATIONS = 1000
jest.setTimeout(ITERATIONS * 10)
......@@ -111,15 +128,10 @@ describe("drawing app mesh", () => {
[0, 0],
])
} else {
console.log(
`single draw and erase (${ITERATIONS} iterations):\n\taddPath: ${(
addTime /
(1e6 * ITERATIONS)
).toFixed(3)}ms\n\textendErasureIntervals: ${(
eraseTime /
(1e6 * ITERATIONS)
).toFixed(3)}ms`,
)
printBenchmark("single draw and erase [sequential]", ITERATIONS, {
addPath: addTime,
extendErasureIntervals: eraseTime,
})
resolve()
}
......@@ -130,4 +142,62 @@ describe("drawing app mesh", () => {
dotIDs.push(room.addPath([209, 88, 5.000000000000001, "#0000ff"]))
})
})
it("benchmarks a single draw and erase update in parallel", () => {
const ITERATIONS = 1000
jest.setTimeout(ITERATIONS * 10)
const dotIDs = []
let prevTime
let addTime
let eraseTime
let timeout
return new Promise((resolve) => {
broadcastListener.callback = () => {
const currTime = process.hrtime()
addTime =
(currTime[0] - prevTime[0]) * 1e9 + (currTime[1] - prevTime[1])
clearTimeout(timeout)
setTimeout(() => resolve(), 1000)
}
prevTime = process.hrtime()
for (let i = 0; i < ITERATIONS; i++) {
dotIDs.push(room.addPath([209, 88, 5.000000000000001, "#0000ff"]))
}
}).then(
() =>
new Promise((resolve) => {
broadcastListener.callback = () => {
const currTime = process.hrtime()
eraseTime =
(currTime[0] - prevTime[0]) * 1e9 + (currTime[1] - prevTime[1])
clearTimeout(timeout)
setTimeout(() => {
printBenchmark("single draw and erase [parallel]", ITERATIONS, {
addPath: addTime,
extendErasureIntervals: eraseTime,
})
resolve()
}, 1000)
}
prevTime = process.hrtime()
for (let i = 0; i < ITERATIONS; i++) {
room.extendErasureIntervals(dotIDs[i], 0, [[0, 0]])
}
}),
)
})
})
This diff is collapsed.
......@@ -49,6 +49,7 @@
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.6.0",
"chalk": "^3.0.0",
"eslint": "^6.5.1",
"eslint-config-prettier": "^6.5.0",
"eslint-plugin-testcafe": "^0.2.1",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment