mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-03-17 03:11:01 +00:00
Refactor: Remove stale benchmark outputs
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
async function createStreamVisualizer(asyncIterable, options) {
|
||||
const { maxPoints, alpha, width, height, yDomain } = options;
|
||||
|
||||
const d3 = await import("https://cdn.jsdelivr.net/npm/d3@7/+esm");
|
||||
|
||||
const data = [];
|
||||
let prevEma = null;
|
||||
|
||||
for await (const { timestamp, value } of asyncIterable) {
|
||||
const ema = prevEma === null
|
||||
? value
|
||||
: alpha * value + (1 - alpha) * prevEma;
|
||||
prevEma = ema;
|
||||
data.push({ timestamp, value, ema });
|
||||
if (data.length > maxPoints) data.shift();
|
||||
}
|
||||
|
||||
const xScale = d3.scaleLinear()
|
||||
.domain([data[0].timestamp, data[data.length - 1].timestamp])
|
||||
.range([0, width]);
|
||||
|
||||
const yScale = d3.scaleLinear()
|
||||
.domain(yDomain)
|
||||
.range([height, 0]);
|
||||
|
||||
const lineGen = d3.line()
|
||||
.x(d => xScale(d.timestamp))
|
||||
.y(d => yScale(d.ema));
|
||||
|
||||
const path = lineGen(data);
|
||||
|
||||
return { data, path };
|
||||
}
|
||||
export default createStreamVisualizer;
|
||||
// Generation time: 4.923s
|
||||
// Result: PASS
|
||||
@@ -1,36 +0,0 @@
|
||||
async function createStreamVisualizer(asyncIterable, options) {
|
||||
const { maxPoints, alpha, width, height, yDomain } = options;
|
||||
|
||||
const d3 = await import("https://cdn.jsdelivr.net/npm/d3@7/+esm");
|
||||
|
||||
const data = [];
|
||||
let prevEma = null;
|
||||
|
||||
for await (const { timestamp, value } of asyncIterable) {
|
||||
const ema = prevEma === null
|
||||
? value
|
||||
: alpha * value + (1 - alpha) * prevEma;
|
||||
prevEma = ema;
|
||||
data.push({ timestamp, value, ema });
|
||||
if (data.length > maxPoints) data.shift();
|
||||
}
|
||||
|
||||
const xScale = d3.scaleLinear()
|
||||
.domain([data[0].timestamp, data[data.length - 1].timestamp])
|
||||
.range([0, width]);
|
||||
|
||||
const yScale = d3.scaleLinear()
|
||||
.domain(yDomain)
|
||||
.range([height, 0]);
|
||||
|
||||
const lineGen = d3.line()
|
||||
.x(d => xScale(d.timestamp))
|
||||
.y(d => yScale(d.ema));
|
||||
|
||||
const path = lineGen(data);
|
||||
|
||||
return { data, path };
|
||||
}
|
||||
export default createStreamVisualizer;
|
||||
// Generation time: 5.157s
|
||||
// Result: PASS
|
||||
@@ -1,33 +0,0 @@
|
||||
export async function createStreamVisualizer(asyncIterable, { maxPoints, alpha, width, height, yDomain }) {
|
||||
const d3 = await import("https://cdn.skypack.dev/d3@7");
|
||||
let data = [];
|
||||
let ema = null;
|
||||
|
||||
for await (const { timestamp, value } of asyncIterable) {
|
||||
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 lineGenerator = d3.line()
|
||||
.x(d => x(d.timestamp))
|
||||
.y(d => y(d.ema));
|
||||
|
||||
return {
|
||||
data,
|
||||
path: lineGenerator(data)
|
||||
};
|
||||
}
|
||||
export default createStreamVisualizer;
|
||||
// Generation time: 11.081s
|
||||
// Result: PASS
|
||||
@@ -1,43 +0,0 @@
|
||||
export async function createStreamVisualizer(asyncIterable, options) {
|
||||
const { maxPoints, alpha, width, height, yDomain } = options;
|
||||
const d3 = await import('https://cdn.jsdelivr.net/npm/d3@7/+esm');
|
||||
|
||||
const data = [];
|
||||
let prevEma = null;
|
||||
|
||||
for await (const point of asyncIterable) {
|
||||
const { timestamp, value } = point;
|
||||
const ema = prevEma === null
|
||||
? value
|
||||
: alpha * value + (1 - alpha) * prevEma;
|
||||
prevEma = ema;
|
||||
|
||||
data.push({ timestamp, value, ema });
|
||||
if (data.length > maxPoints) {
|
||||
data.shift();
|
||||
}
|
||||
}
|
||||
|
||||
if (data.length === 0) {
|
||||
return { data: [], path: '' };
|
||||
}
|
||||
|
||||
const [first, last] = [data[0], data[data.length - 1]];
|
||||
const xScale = d3.scaleLinear()
|
||||
.domain([first.timestamp, last.timestamp])
|
||||
.range([0, width]);
|
||||
|
||||
const yScale = d3.scaleLinear()
|
||||
.domain(yDomain)
|
||||
.range([height, 0]);
|
||||
|
||||
const path = d3.line()
|
||||
.x(d => xScale(d.timestamp))
|
||||
.y(d => yScale(d.ema))
|
||||
.curve(d3.curveLinear)(data);
|
||||
|
||||
return { data, path };
|
||||
}
|
||||
export default createStreamVisualizer;
|
||||
// Generation time: 20.632s
|
||||
// Result: PASS
|
||||
@@ -1,55 +0,0 @@
|
||||
export async function createStreamVisualizer(stream, opts = {}) {
|
||||
const {
|
||||
maxPoints = 1000,
|
||||
alpha = 0.2,
|
||||
width = 800,
|
||||
height = 300,
|
||||
yDomain = [-1, 1]
|
||||
} = opts;
|
||||
|
||||
if (alpha <= 0 || alpha >= 1 || !Number.isFinite(alpha))
|
||||
throw new Error('alpha must be in (0,1)');
|
||||
if (!Array.isArray(yDomain) || yDomain.length !== 2 || !yDomain.every(Number.isFinite))
|
||||
throw new Error('yDomain must be a [min, max] pair of numbers');
|
||||
|
||||
const d3 = await import('https://cdn.jsdelivr.net/npm/d3@7/+esm');
|
||||
|
||||
const buf = [];
|
||||
let prevEma = undefined;
|
||||
|
||||
for await (const p of stream) {
|
||||
if (!p || !('timestamp' in p) || !('value' in p)) continue;
|
||||
const v = Number(p.value);
|
||||
if (!Number.isFinite(v)) continue;
|
||||
|
||||
if (prevEma === undefined) prevEma = v;
|
||||
else prevEma = alpha * v + (1 - alpha) * prevEma;
|
||||
|
||||
buf.push({ timestamp: p.timestamp, value: v, ema: prevEma });
|
||||
if (buf.length > maxPoints) buf.shift();
|
||||
}
|
||||
|
||||
const data = buf;
|
||||
let path = '';
|
||||
|
||||
if (data.length) {
|
||||
const xs = d3.scaleLinear()
|
||||
.domain([data[0].timestamp, data[data.length - 1].timestamp])
|
||||
.range([0, width]);
|
||||
|
||||
const ys = d3.scaleLinear()
|
||||
.domain(yDomain)
|
||||
.range([height, 0]);
|
||||
|
||||
const line = d3.line()
|
||||
.x(d => xs(d.timestamp))
|
||||
.y(d => ys(d.ema));
|
||||
|
||||
path = line(data) || '';
|
||||
}
|
||||
|
||||
return { data, path };
|
||||
}
|
||||
export default createStreamVisualizer;
|
||||
// Generation time: 14.769s
|
||||
// Result: PASS
|
||||
@@ -1,21 +0,0 @@
|
||||
async function createStreamVisualizer(asyncIterable, { maxPoints, alpha, width, height, yDomain }) {
|
||||
const d3 = await import('d3'), data = [];
|
||||
let pe;
|
||||
|
||||
for await (const { timestamp: t, value: v } of asyncIterable) {
|
||||
const ema = pe === undefined ? v : alpha * v + (1 - alpha) * pe;
|
||||
pe = ema;
|
||||
data.push({ timestamp: t, value: v, ema });
|
||||
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]);
|
||||
|
||||
return { data, path: d3.line().x(d => x(d.timestamp)).y(d => y(d.ema))(data) };
|
||||
}
|
||||
export default createStreamVisualizer;
|
||||
// Generation time: 81.116s
|
||||
// Result: FAIL
|
||||
@@ -1,20 +0,0 @@
|
||||
async function createStreamVisualizer(it,o={}){
|
||||
let{maxPoints=100,alpha=.3,width=300,height=150,yDomain:[y0,y1]=[0,1]}=o
|
||||
let{scaleLinear,line}=await import('https://cdn.jsdelivr.net/npm/d3@7/+esm')
|
||||
let d=[],e
|
||||
for await(let{timestamp:t,value:v}of it){
|
||||
e=e==null?v:alpha*v+(1-alpha)*e
|
||||
d.push({timestamp:+t,value:v,ema:e})
|
||||
d.length>maxPoints&&d.shift()
|
||||
}
|
||||
let p=''
|
||||
if(d.length){
|
||||
let x=scaleLinear().domain([d[0].timestamp,d.at(-1).timestamp]).range([0,width])
|
||||
let y=scaleLinear().domain([y0,y1]).range([height,0])
|
||||
p=line().x(a=>x(a.timestamp)).y(a=>y(a.ema))(d)||''
|
||||
}
|
||||
return{data:d,path:p}
|
||||
}
|
||||
export default createStreamVisualizer;
|
||||
// Generation time: 25.168s
|
||||
// Result: PASS
|
||||
@@ -1,21 +0,0 @@
|
||||
async function createStreamVisualizer(iterable,options={}){
|
||||
const{maxPoints=100,alpha=.3,width=640,height=320,yDomain=[0,1]}=options
|
||||
const{scaleLinear,line}=await import('https://cdn.jsdelivr.net/npm/d3@7/+esm')
|
||||
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})
|
||||
data.length>maxPoints&&data.shift()
|
||||
}
|
||||
let path=''
|
||||
if(data.length){
|
||||
const x=scaleLinear().domain([data[0].timestamp,data.at(-1).timestamp]).range([0,width])
|
||||
const y=scaleLinear().domain(yDomain).range([height,0])
|
||||
path=line().x(d=>x(d.timestamp)).y(d=>y(d.ema))(data)||''
|
||||
}
|
||||
return{data,path}
|
||||
}
|
||||
export default createStreamVisualizer;
|
||||
// Generation time: 10.093s
|
||||
// Result: PASS
|
||||
@@ -1,77 +0,0 @@
|
||||
const d3Url = "https://cdn.jsdelivr.net/npm/d3@7/+esm";
|
||||
let d3p;
|
||||
|
||||
const loadD3 = () => d3p || (d3p = import(d3Url));
|
||||
const toNum = v => (typeof v == "string" && !v.trim() ? NaN : +v);
|
||||
const toTime = t => (t instanceof Date ? +t : typeof t == "string" && isNaN(+t) ? Date.parse(t) : +t);
|
||||
|
||||
const asPoint = p => {
|
||||
if (p == null) return {};
|
||||
if (typeof p == "number") return { timestamp: Date.now(), value: p };
|
||||
if (Array.isArray(p)) return { timestamp: toTime(p[0]), value: toNum(p[1]) };
|
||||
if (typeof p == "object")
|
||||
return {
|
||||
timestamp: toTime(p.timestamp ?? p.time ?? p.t),
|
||||
value: toNum(p.value ?? p.v ?? p.y)
|
||||
};
|
||||
return {};
|
||||
};
|
||||
|
||||
async function createStreamVisualizer(asyncIterable, o = {}) {
|
||||
const { scaleLinear, line } = await loadD3();
|
||||
|
||||
let {
|
||||
maxPoints = 500,
|
||||
alpha = 0.2,
|
||||
width = 600,
|
||||
height = 200,
|
||||
yDomain = [0, 1]
|
||||
} = o;
|
||||
|
||||
maxPoints =
|
||||
maxPoints === Infinity
|
||||
? Infinity
|
||||
: Number.isFinite(+maxPoints)
|
||||
? Math.max(1, Math.floor(+maxPoints))
|
||||
: 500;
|
||||
|
||||
alpha = Number.isFinite(+alpha) ? Math.min(1, Math.max(0, +alpha)) : 0.2;
|
||||
width = Math.max(0, +width || 0);
|
||||
height = Math.max(0, +height || 0);
|
||||
|
||||
const data = [];
|
||||
let ema, seeded = false;
|
||||
|
||||
for await (const item of asyncIterable) {
|
||||
const { timestamp, value } = asPoint(item);
|
||||
if (!Number.isFinite(timestamp) || !Number.isFinite(value)) continue;
|
||||
|
||||
ema = seeded ? alpha * value + (1 - alpha) * ema : (seeded = true, value);
|
||||
data.push({ timestamp, value, ema });
|
||||
if (data.length > maxPoints) data.splice(0, data.length - maxPoints);
|
||||
}
|
||||
|
||||
if (!data.length) return { data, path: "" };
|
||||
|
||||
let t0 = data[0].timestamp,
|
||||
t1 = data[data.length - 1].timestamp;
|
||||
if (t0 === t1) t1 = t0 + 1;
|
||||
|
||||
let [y0, y1] = Array.isArray(yDomain) ? yDomain : [0, 1];
|
||||
y0 = toNum(y0);
|
||||
y1 = toNum(y1);
|
||||
if (!Number.isFinite(y0) || !Number.isFinite(y1)) (y0 = 0), (y1 = 1);
|
||||
if (y0 === y1) y1 = y0 + 1;
|
||||
|
||||
const x = scaleLinear().domain([t0, t1]).range([0, width]);
|
||||
const y = scaleLinear().domain([y0, y1]).range([height, 0]);
|
||||
|
||||
const path = line()
|
||||
.x(d => x(d.timestamp))
|
||||
.y(d => y(d.ema))(data) || "";
|
||||
|
||||
return { data, path };
|
||||
}
|
||||
export default createStreamVisualizer;
|
||||
// Generation time: 140.623s
|
||||
// Result: PASS
|
||||
Reference in New Issue
Block a user