Docs: Update benchmark results

This commit is contained in:
github-actions[bot]
2025-11-18 23:31:52 +00:00
parent 341252fec1
commit 5855cf8a6f
77 changed files with 972 additions and 1051 deletions

View File

@@ -11,9 +11,7 @@ export async function createStreamVisualizer(asyncIterable, options) {
: alpha * value + (1 - alpha) * prevEma;
data.push({ timestamp, value, ema });
if (data.length > maxPoints) data.shift();
prevEma = ema;
}

View File

@@ -1,50 +1,33 @@
async function createStreamVisualizer(asyncIterable, {
maxPoints,
alpha,
width,
height,
yDomain
}) {
const {
scaleLinear,
line
} = await import('d3');
async function createStreamVisualizer(
asyncIterable,
{ maxPoints, alpha, width, height, yDomain }
) {
const { scaleLinear, line } = await import('d3');
const data = [];
let prevEma;
let ema = null;
for await (const { value, timestamp } of asyncIterable) {
prevEma = (prevEma === undefined) ?
value :
alpha * value + (1 - alpha) * prevEma;
data.push({
timestamp,
value,
ema: prevEma
});
for await (const point of asyncIterable) {
ema = ema === null ? point.value : alpha * point.value + (1 - alpha) * ema;
data.push({ ...point, ema });
if (data.length > maxPoints) {
data.shift();
}
}
if (!data.length) {
return {
data,
path: ''
};
if (data.length < 2) {
return { data, path: "" };
}
const x = scaleLinear([data[0].timestamp, data.at(-1).timestamp], [0, width]);
const x = scaleLinear(
[data[0].timestamp, data.at(-1).timestamp],
[0, width]
);
const y = scaleLinear(yDomain, [height, 0]);
const path = line()
.x(d => x(d.timestamp))
.y(d => y(d.ema))(data);
.x(p => x(p.timestamp))
.y(p => y(p.ema))(data);
return {
data,
path: path ?? ''
};
return { data, path };
}
export default createStreamVisualizer;

View File

@@ -0,0 +1,28 @@
export const createStreamVisualizer = async (stream, { maxPoints, alpha, width, height, yDomain }) => {
const { scaleLinear, scaleTime, line } = await import('https://esm.sh/d3@7');
const data = [];
let ema;
for await (const { timestamp, value } of stream) {
ema = ema === undefined ? 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 = scaleTime()
.domain([data[0].timestamp, data.at(-1).timestamp])
.range([0, width]);
const y = scaleLinear()
.domain(yDomain)
.range([height, 0]);
const path = line()
.x(d => x(d.timestamp))
.y(d => y(d.ema))(data);
return { data, path };
};
export default createStreamVisualizer;

View File

@@ -1,32 +0,0 @@
export const createStreamVisualizer = async (
stream,
{ maxPoints, alpha, width, height, yDomain }
) => {
const { scaleLinear, line } = await import('https://cdn.jsdelivr.net/npm/d3@7/+esm');
const data = [];
let prev = null;
for await (const { timestamp, value } of stream) {
const ema = prev == null ? value : alpha * value + (1 - alpha) * prev;
prev = ema;
data.push({ timestamp, value, ema });
if (data.length > maxPoints) data.shift();
}
if (!data.length) return { data, path: '' };
const x = scaleLinear()
.domain([data[0].timestamp, data[data.length - 1].timestamp])
.range([0, width]);
const y = scaleLinear()
.domain(yDomain)
.range([height, 0]);
const curve = line()
.x(d => x(d.timestamp))
.y(d => y(d.ema));
return { data, path: curve(data) };
};
export default createStreamVisualizer;

View File

@@ -1,68 +1,20 @@
async function createStreamVisualizer(asyncIterable, options) {
const { maxPoints, alpha, width, height, yDomain } = options;
const d3 = await import('https://cdn.jsdelivr.net/npm/d3@7/+esm');
if (!Number.isFinite(maxPoints) || maxPoints < 1) {
throw new Error('maxPoints must be a positive integer');
}
if (!Number.isFinite(alpha) || alpha < 0 || alpha > 1) {
throw new Error('alpha must be between 0 and 1');
}
if (!Array.isArray(yDomain) || yDomain.length !== 2) {
throw new Error('yDomain must be an array of [min, max]');
}
if (!Number.isFinite(width) || width <= 0) {
throw new Error('width must be a positive number');
}
if (!Number.isFinite(height) || height <= 0) {
throw new Error('height must be a positive number');
}
export async function createStreamVisualizer(stream, { maxPoints, alpha, width, height, yDomain }) {
const d3 = await import('d3');
const data = [];
let prevEma = null;
let itemCount = 0;
for await (const value of asyncIterable) {
if (!Number.isFinite(value)) {
throw new Error('Stream must yield finite numeric values');
}
const timestamp = Date.now();
const ema = prevEma === null ? value : alpha * value + (1 - alpha) * prevEma;
const point = { timestamp, value, ema };
if (itemCount < maxPoints) {
data.push(point);
itemCount++;
} else {
data.shift();
data.push(point);
}
prevEma = ema;
let ema = null;
for await (const { timestamp, value } of stream) {
ema = ema === null ? value : alpha * value + (1 - alpha) * ema;
data.push({ timestamp, value, ema });
if (data.length > maxPoints) data.shift();
}
let path = '';
if (data.length > 0) {
const xDomain = data.length > 1 ? [data[0].timestamp, data[data.length - 1].timestamp] : [data[0].timestamp - 1000, data[0].timestamp];
const xScale = d3.scaleLinear()
.domain(xDomain)
.range([0, width]);
const yScale = d3.scaleLinear()
.domain(yDomain)
.range([height, 0]);
const line = d3.line()
.x(d => xScale(d.timestamp))
.y(d => yScale(d.ema))
.curve(d3.curveMonotoneX)
.defined(d => Number.isFinite(d.ema));
path = line(data) || '';
}
if (!data.length) return { data, path: '' };
const x = d3.scaleLinear().domain([data[0].timestamp, data[data.length - 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;

View File

@@ -1,18 +1,20 @@
const createStreamVisualizer=async(iter,o)=>{
const{maxPoints:m,alpha:a,width:w,height:h,yDomain:Y}=o
const data=[]
const createStreamVisualizer = async (src, opt = {}) => {
const { maxPoints = 100, alpha = 0.5, width = 600, height = 300, yDomain = [0, 1] } = opt
const { scaleLinear, line } = await import('https://cdn.jsdelivr.net/npm/d3@7/+esm')
const data = []
let ema
for await(const {timestamp:t,value:v} of iter){
const d=new Date(t)
ema=ema==null?v:a*v+(1-a)*ema
data.push({timestamp:d,value:v,ema})
if(data.length>m)data.shift()
for await (const p of src) {
if (!p) continue
const { timestamp: t, value: v } = p
if (t == null || v == null) continue
ema = ema == null ? v : alpha * v + (1 - alpha) * ema
data.push({ timestamp: t, value: v, ema })
data.length > maxPoints && data.shift()
}
if(!data.length)return{data,path:''}
const{scaleTime,scaleLinear,line}=await import('https://cdn.skypack.dev/d3@7?min')
const x=scaleTime().domain([data[0].timestamp,data[data.length-1].timestamp]).range([0,w])
const y=scaleLinear().domain(Y).range([h,0])
const path=line().x(d=>x(d.timestamp)).y(d=>y(d.ema))(data)||''
return{data,path}
if (!data.length) return { data, path: '' }
const x = scaleLinear().domain([data[0].timestamp, data.at(-1).timestamp]).range([0, width])
const y = scaleLinear().domain(yDomain).range([height, 0])
const path = line().x(d => x(d.timestamp)).y(d => y(d.ema))(data) || ''
return { data, path }
}
export default createStreamVisualizer;

View File

@@ -1,19 +1,17 @@
async function createStreamVisualizer(asyncIterable,options){
const{maxPoints,alpha,width,height,yDomain}=options;
const{scaleLinear:sl,line}=await import('https://cdn.skypack.dev/d3');
let points=[];
let prevEma=NaN;
for await(const{timestamp,value}of asyncIterable){
const ema=isNaN(prevEma)?value:alpha*value+(1-alpha)*prevEma;
points.push({timestamp,value,ema});
prevEma=ema;
if(points.length>maxPoints)points.shift();
async function createStreamVisualizer(iter,opts={}){
const{maxPoints:mp=1e3,alpha:a=.1,width:w=800,height:h=400,yDomain:yd=[0,1]}=opts;
let data=[],pE=null;
for await(const{timestamp:t,value:v}of iter){
let ema=pE===null?v:a*v+(1-a)*pE;
pE=ema;
data.push({timestamp:t,value:v,ema});
if(data.length>mp)data.shift();
}
if(!points.length)return{data:[],path:''};
const xDomain=[points[0].timestamp,points[points.length-1].timestamp];
const x=sl().domain(xDomain).range([0,width]);
const y=sl().domain(yDomain).range([height,0]);
const lineGen=line().x(d=>x(d.timestamp)).y(d=>y(d.ema));
return{data:points,path:lineGen(points)};
if(!data.length)return{data,path:null};
const d3=await import('https://cdn.skypack.dev/d3');
const x=d3.scaleLinear().domain([data[0].timestamp,data.at(-1).timestamp]).range([0,w]);
const y=d3.scaleLinear().domain(yd).range([h,0]);
const ln=d3.line().x(d=>x(d.timestamp)).y(d=>y(d.ema));
return{data,path:ln(data)};
}
export default createStreamVisualizer;