mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-03-17 11:21:00 +00:00
Refactor: Remove stale benchmark outputs
This commit is contained in:
@@ -1,48 +0,0 @@
|
||||
async function createStreamVisualizer(asyncIterable, o = {}) {
|
||||
let {
|
||||
maxPoints = 500,
|
||||
alpha = 0.2,
|
||||
width = 600,
|
||||
height = 200,
|
||||
yDomain = [0, 1]
|
||||
} = o
|
||||
|
||||
alpha = +alpha
|
||||
if (!(alpha >= 0 && alpha <= 1)) alpha = 0.2
|
||||
|
||||
let d3 = await import("https://cdn.jsdelivr.net/npm/d3@7/+esm")
|
||||
let data = [], ema, seeded = false
|
||||
|
||||
for await (let p of asyncIterable) {
|
||||
let timestamp, value
|
||||
|
||||
if (Array.isArray(p)) [timestamp, value] = p
|
||||
else if (p && typeof p == "object") ({ timestamp, value } = p)
|
||||
else (timestamp = Date.now()), (value = p)
|
||||
|
||||
timestamp = +timestamp
|
||||
value = +value
|
||||
|
||||
if (!seeded) (ema = value), (seeded = true)
|
||||
else ema = alpha * value + (1 - alpha) * ema
|
||||
|
||||
data.push({ timestamp, value, ema })
|
||||
|
||||
if (data.length > maxPoints) data.splice(0, data.length - maxPoints)
|
||||
}
|
||||
|
||||
let path = ""
|
||||
if (data.length) {
|
||||
let t0 = data[0].timestamp, t1 = data.at(-1).timestamp
|
||||
if (t0 === t1) t1 = t0 + 1
|
||||
|
||||
let x = d3.scaleLinear().domain([t0, t1]).range([0, width])
|
||||
let y = d3.scaleLinear().domain(yDomain).range([height, 0])
|
||||
path = d3.line().x(d => x(d.timestamp)).y(d => y(d.ema))(data) || ""
|
||||
}
|
||||
|
||||
return { data, path }
|
||||
}
|
||||
export default createStreamVisualizer;
|
||||
// Generation time: 18.105s
|
||||
// Result: PASS
|
||||
@@ -1,17 +0,0 @@
|
||||
async function createStreamVisualizer(src,{maxPoints=500,alpha=.5,width=800,height=600,yDomain}){
|
||||
const d3=await import('https://cdn.jsdelivr.net/npm/d3@7')
|
||||
const d=[];let e
|
||||
for await(const{timestamp:t,value:v}of src){
|
||||
e=e===undefined?v:alpha*v+(1-alpha)*e
|
||||
d.push({timestamp:t,value:v,ema:e})
|
||||
if(d.length>maxPoints)d.shift()
|
||||
}
|
||||
if(!d.length)return{data:[],path:''}
|
||||
const x=d3.scaleLinear().domain([d[0].timestamp,d.at(-1).timestamp]).range([0,width])
|
||||
const y=d3.scaleLinear().domain(yDomain||[d3.min(d,d=>d.ema),d3.max(d,d=>d.ema)]).range([height,0])
|
||||
const p=d3.line().x(v=>x(v.timestamp)).y(v=>y(v.ema)).curve(d3.curveLinear)
|
||||
return{data:d,path:p(d)}
|
||||
}
|
||||
export default createStreamVisualizer;
|
||||
// Generation time: 1.456s
|
||||
// Result: FAIL
|
||||
@@ -1,30 +0,0 @@
|
||||
const createStreamVisualizer = async (iterable, { maxPoints, alpha, width, height, yDomain }) => {
|
||||
const d3 = await import('https://esm.sh/d3');
|
||||
const data = [];
|
||||
let ema;
|
||||
|
||||
for await (const { timestamp, value } of iterable) {
|
||||
ema = ema == null ? value : alpha * value + (1 - alpha) * ema;
|
||||
data.push({ timestamp, value, ema });
|
||||
if (data.length > maxPoints) data.shift();
|
||||
}
|
||||
|
||||
if (!data.length) return { data, path: '' };
|
||||
|
||||
const x = d3.scaleLinear()
|
||||
.domain([data[0].timestamp, data.at(-1).timestamp])
|
||||
.range([0, width]);
|
||||
const y = d3.scaleLinear()
|
||||
.domain(yDomain)
|
||||
.range([height, 0]);
|
||||
|
||||
const path = d3.line()
|
||||
.x(d => x(d.timestamp))
|
||||
.y(d => y(d.ema))
|
||||
(data);
|
||||
|
||||
return { data, path };
|
||||
};
|
||||
export default createStreamVisualizer;
|
||||
// Generation time: 253.115s
|
||||
// Result: PASS
|
||||
Reference in New Issue
Block a user