Published
Edited
Mar 29, 2022
1 fork
1 star
Insert cell
Insert cell
Insert cell
results = {
return new Promise((resolve) => {
const results = [];
const s = new Benchmark.Suite("splice");

let x = Array.from({ length: 1000 }, (_, i) => i);
let input = Array.from({ length: 100 }, (_, i) => i);

s.add("splice", function () {
x.slice().splice(100, 0, ...input);
})
.add("slice", function () {
x.slice(0, 100).concat(input).concat(x.slice(100));
})
.on("cycle", (e) => results.push(String(e.target)))
.on("finish", resolve(results))
.run();
});
}
Insert cell
Benchmark = require("benchmark")
Insert cell
viewof target = Inputs.range([0, 10], { step: 1 })
Insert cell
{
//splice method
let x = Array.from({ length: 10 }, (_, i) => i);
let input = Array.from({ length: 3 }, (_, i) => i + 10000);
x.splice(target, 0, ...input);
return x;
}
Insert cell
{
//slice+concat method
let x = Array.from({ length: 10 }, (_, i) => i);
let input = Array.from({ length: 3 }, (_, i) => i + 10000);
return x.slice(0, target).concat(input).concat(x.slice(target));
}
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