Published
Edited
Feb 28, 2020
5 stars
Insert cell
Insert cell
{ yield 42; }
Insert cell
Insert cell
{ for (let i = 1; i <= 10; i++) yield i; }
Insert cell
Insert cell
{
let start = performance.now();
let to = 100000;
let sum = 0;
for (let i = 1; i <= to; i++) {};
return `Counting to ${to} took ${(performance.now() - start).toFixed(2)} milliseconds`;
}
Insert cell
Insert cell
{
let to = 60;
let start = performance.now();
for (let i = 0; i < to; i++) yield i;
yield `Counting to ${to} took ${(performance.now() - start).toFixed(2)} milliseconds`;
}
Insert cell
Insert cell
{
let timings = [];
for (let batchSize of [100, 1000, 5000]) {
let start = performance.now();
for (let i = 0; i < 10000; i += batchSize) {
let numbers = [];
for (let j = i; j < i + batchSize; j++) numbers.push(j * 2);
yield numbers;
}
timings.push(
`| ${batchSize} | ${(performance.now() - start).toFixed(2)} |`
);
}
yield md`| batch size | milliseconds |
| --- | --- | --- |
${timings.join("\n")}`;
}
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more