mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-03-17 03:11:01 +00:00
Docs: Update benchmark for openrouter/hunter-alpha
This commit is contained in:
36
tests/9_stream_visualizer/outputs/openrouter_hunter-alpha.js
Normal file
36
tests/9_stream_visualizer/outputs/openrouter_hunter-alpha.js
Normal file
@@ -0,0 +1,36 @@
|
||||
async function createStreamVisualizer(asyncIterable, options) {
|
||||
const { maxPoints, alpha, width, height, yDomain } = options;
|
||||
const data = [];
|
||||
let ema;
|
||||
|
||||
for await (const point of asyncIterable) {
|
||||
if (ema === undefined) {
|
||||
ema = point.value;
|
||||
} else {
|
||||
ema = alpha * point.value + (1 - alpha) * ema;
|
||||
}
|
||||
|
||||
data.push({ timestamp: point.timestamp, value: point.value, ema });
|
||||
if (data.length > maxPoints) {
|
||||
data.shift();
|
||||
}
|
||||
}
|
||||
|
||||
if (data.length === 0) {
|
||||
return { data, path: '' };
|
||||
}
|
||||
|
||||
const d3 = await import('https://cdn.jsdelivr.net/npm/d3@7/+esm');
|
||||
const xDomain = [data[0].timestamp, data[data.length - 1].timestamp];
|
||||
const xScale = d3.scaleLinear().domain(xDomain).range([0, width]);
|
||||
const yScale = d3.scaleLinear().domain(yDomain).range([height, 0]);
|
||||
|
||||
const lineGenerator = d3.line()
|
||||
.x(d => xScale(d.timestamp))
|
||||
.y(d => yScale(d.ema));
|
||||
|
||||
return { data, path: lineGenerator(data) };
|
||||
}
|
||||
export default createStreamVisualizer;
|
||||
// Generation time: 21.308s
|
||||
// Result: PASS
|
||||
Reference in New Issue
Block a user