mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-14 08:37:56 +00:00
Docs: Update benchmark results
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user