perf-deets
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -41,3 +41,3 @@ import * as Plot from '@observablehq/plot'; | ||
function appendPerfResults(name, data) { | ||
function append(name) { | ||
// We track which data has been output, and after a certain time | ||
@@ -121,2 +121,8 @@ // assue things have settled and remove any stale data. We do this | ||
return { c, r }; | ||
} | ||
function appendTimingResults(name, data) { | ||
let { c, r } = append(name); | ||
let svgCont = document.createElement('div'); | ||
@@ -184,3 +190,2 @@ svgCont.className = 'data ' + name; | ||
let existing = r.querySelector('.data.' + name); | ||
console.log(name, existing); | ||
if (existing) { | ||
@@ -193,2 +198,57 @@ existing.parentNode.replaceChild(svgCont, existing); | ||
function appendCountResults(name, data) { | ||
let { c, r } = append(name); | ||
let svgCont = document.createElement('div'); | ||
svgCont.className = 'data ' + name; | ||
svgCont.dataset.dataName = name; | ||
svgCont.style.marginTop = '15px'; | ||
let text = document.createElement('div'); | ||
text.style.font = '13px system-ui, sans-serif'; | ||
text.style.display = 'flex'; | ||
text.style.justifyContent = 'space-between'; | ||
let label = document.createElement('div'); | ||
label.textContent = name; | ||
text.appendChild(label); | ||
let spacer = document.createElement('div'); | ||
spacer.style.flex = '1'; | ||
text.appendChild(spacer); | ||
text.appendChild(makeDataPoint('count', data.length)); | ||
svgCont.appendChild(text); | ||
let svg = Plot.plot({ | ||
y: { grid: true, label: 'count', labelOffset: 40, inset: 10 }, | ||
x: { grid: true, label: 'run time (ms)', labelOffset: 40 }, | ||
marginTop: 30, | ||
marginLeft: 50, | ||
marginRight: 30, | ||
marginBottom: 50, | ||
marks: [Plot.line(data, { x: 'x', y: 'y' })] | ||
}); | ||
svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg'); | ||
svg.setAttribute('version', '1.1'); | ||
svg.setAttribute('preserveAspectRatio', 'none'); | ||
svg.style.font = '13px system-ui, sans-serif'; | ||
svg.style.backgroundColor = 'white'; | ||
svg.style.marginTop = '5px'; | ||
let scale = 1.5; | ||
svg.setAttribute('width', 640 * (scale / 2)); | ||
svg.setAttribute('height', 400 * (scale / 2)); | ||
svgCont.appendChild(svg); | ||
let existing = r.querySelector('.data.' + name); | ||
if (existing) { | ||
existing.parentNode.replaceChild(svgCont, existing); | ||
} else { | ||
r.appendChild(svgCont); | ||
} | ||
} | ||
let listenedWorkers = new WeakSet(); | ||
@@ -207,3 +267,8 @@ | ||
case 'log-perf': { | ||
appendPerfResults(msg.data.name, msg.data.data); | ||
switch (msg.data.dataType) { | ||
case 'timing': | ||
appendTimingResults(msg.data.name, msg.data.data); | ||
case 'count': | ||
appendCountResults(msg.data.name, msg.data.data); | ||
} | ||
break; | ||
@@ -210,0 +275,0 @@ } |
{ | ||
"name": "perf-deets", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"main": "./perf.js", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
34
perf.js
let buffer = 40000; | ||
let baseTime; | ||
let timings = {}; | ||
let counts = []; | ||
@@ -16,16 +17,20 @@ const descriptions = { | ||
async function writeData(name, data) { | ||
self.postMessage({ type: 'log-perf', name, data }); | ||
async function writeData(type, name, data) { | ||
self.postMessage({ type: 'log-perf', dataType: type, name, data }); | ||
} | ||
export async function end() { | ||
await Promise.all( | ||
Object.keys(timings).map(name => { | ||
let timing = timings[name]; | ||
return writeData( | ||
name, | ||
timing.data.map(x => ({ x: x.start + x.took, y: x.took })) | ||
); | ||
}) | ||
); | ||
Object.keys(timings).map(name => { | ||
let timing = timings[name]; | ||
writeData( | ||
'timing', | ||
name, | ||
timing.data.map(x => ({ x: x.start + x.took, y: x.took })) | ||
); | ||
}); | ||
Object.keys(counts).map(name => { | ||
let count = counts[name]; | ||
writeData('count', name, count.map((c, i) => ({ x: c.time, y: i }))); | ||
}); | ||
} | ||
@@ -66,1 +71,8 @@ | ||
} | ||
export function count(name) { | ||
if (counts[name] == null) { | ||
counts[name] = []; | ||
} | ||
counts[name].push({ time: performance.now() }); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9322
294