Docs: Update benchmark results

This commit is contained in:
github-actions[bot]
2025-11-18 17:37:06 +00:00
parent 39d057f079
commit afcfd09537
84 changed files with 1086 additions and 1088 deletions

View File

@@ -6,9 +6,14 @@ export async function createStreamVisualizer(asyncIterable, options) {
let prevEma;
for await (const { timestamp, value } of asyncIterable) {
const ema = prevEma === undefined ? value : alpha * value + (1 - alpha) * prevEma;
const ema = prevEma === undefined
? value
: alpha * value + (1 - alpha) * prevEma;
data.push({ timestamp, value, ema });
if (data.length > maxPoints) data.shift();
prevEma = ema;
}

View File

@@ -11,42 +11,32 @@ async function createStreamVisualizer(asyncIterable, {
} = await import('d3');
const data = [];
let prevEma = null;
let prevEma;
for await (const {
timestamp,
value
} of asyncIterable) {
const ema = prevEma === null ?
for await (const { value, timestamp } of asyncIterable) {
prevEma = (prevEma === undefined) ?
value :
alpha * value + (1 - alpha) * prevEma;
data.push({
timestamp,
value,
ema
ema: prevEma
});
prevEma = ema;
if (data.length > maxPoints) {
data.shift();
}
}
if (data.length < 2) {
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 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))
@@ -54,7 +44,7 @@ async function createStreamVisualizer(asyncIterable, {
return {
data,
path
path: path ?? ''
};
}
export default createStreamVisualizer;

View File

@@ -0,0 +1,32 @@
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,9 +1,68 @@
export async function createStreamVisualizer(i,o){
const d=await import('d3'),{maxPoints:m,alpha:a,width:w,height:h,yDomain:y}=o,p=[],c=d.scaleLinear,f=d.line;
let e;
for await(const{timestamp:t,value:v}of i){e=e===undefined?v:a*v+(1-a)*e;p.push({timestamp:t,value:v,ema:e});p.length>m&&p.shift()}
if(!p.length)return{data:[],path:''};
const x=c().domain([p[0].timestamp,p.at(-1).timestamp]).range([0,w]),z=c().domain(y).range([h,0]),g=f().x(d=>x(d.timestamp)).y(d=>z(d.ema)).curve(d.curveLinear);
return{data:p,path:g(p)}
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');
}
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 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) || '';
}
return { data, path };
}
export default createStreamVisualizer;

View File

@@ -1,23 +0,0 @@
export async function createStreamVisualizer(iter, o) {
const { maxPoints, alpha, width, height, yDomain } = o
const d3 = await import('https://cdn.jsdelivr.net/npm/d3@7/+esm')
const data = []
let ema
for await (const { timestamp, value } of iter) {
ema = ema == null ? value : alpha * value + (1 - alpha) * ema
data.push({ timestamp, value, ema })
if (data.length > maxPoints) data.shift()
}
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))
const path = line(data) || ''
return { data, path }
}
export default createStreamVisualizer;

View File

@@ -1,23 +1,18 @@
async function createStreamVisualizer(iterable, {
maxPoints = 100,
alpha = .5,
width = 300,
height = 150,
yDomain = [0, 1]
} = {}) {
const { scaleLinear, line } = await import('https://cdn.jsdelivr.net/npm/d3@7/+esm')
const data = []
const createStreamVisualizer=async(iter,o)=>{
const{maxPoints:m,alpha:a,width:w,height:h,yDomain:Y}=o
const data=[]
let ema
for await (const point of iterable) {
const { timestamp, value } = point
ema = ema == null ? value : alpha * value + (1 - alpha) * ema
data.push({ timestamp, value, ema })
data.length > maxPoints && data.shift()
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()
}
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 }
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}
}
export default createStreamVisualizer;

View File

@@ -1,26 +0,0 @@
async function createStreamVisualizer(asyncIterable, { maxPoints = 100, alpha = 0.3, width = 800, height = 400, yDomain = [-1, 1] } = {}) {
const { select, scaleLinear, scaleTime, line } = await import('https://cdn.skypack.dev/d3@7');
let data = [], prevEma;
for await (const { timestamp, value } of asyncIterable) {
const ema = prevEma === undefined ? value : alpha * value + (1 - alpha) * prevEma;
prevEma = 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 lineGen = line()
.x(d => x(d.timestamp))
.y(d => y(d.ema))
.curve(select.curveMonotoneX);
return { data, path: lineGen(data) };
}
export default createStreamVisualizer;

View File

@@ -1,16 +1,19 @@
async function createStreamVisualizer(iter,opts){
const{maxPoints:max,alpha,width,height,yDomain}=opts;
let data=[],prev=null;
for await(const i of iter){
const ts=i.timestamp,v=i.value,e=prev==null?v:alpha*v+(1-alpha)*prev;
prev=e;
data.push({timestamp:ts,value:v,ema:e});
if(data.length>max)data.shift();
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();
}
const{scaleLinear,line}=await import('https://cdn.skypack.dev/d3');
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]);
return{data,line().x(d=>x(d.timestamp)).y(d=>y(d.ema))(data)};
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)};
}
export default createStreamVisualizer;