Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Multiple Attributes Performance
(version: 0)
Comparing performance of:
Default vs each with setAttribute vs setAttribute with loop vs Detached
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://d3js.org/d3.v5.min.js"></script>
Script Preparation code:
const data = d3.range(100).map(() => ({ x: Math.random() * 300, y: Math.random() * 150 })); const svg = d3.select("body") .append("svg"); const circles = svg.selectAll("circle") .data(data) .enter() .append("circle") .attr("cx", d=>d.x) .attr("cy", d=>d.y) .attr("r", 2) .style("fill", "teal");
Tests:
Default
const data = d3.range(200).map(() => ({ x: Math.random() * 300, y: Math.random() * 150 })); const svg = d3.select("body") .append("svg"); const circles = svg.selectAll(null) .data(data) .attr("cx", d=>d.x) .attr("cy", d=>d.y) .attr("r", 2) .style("fill", "teal");
each with setAttribute
const data = d3.range(200).map(() => ({ x: Math.random() * 300, y: Math.random() * 150 })); const svg = d3.select("body") .append("svg"); const circles = svg.selectAll("circle") .data(data) .each((d, i, n) => { n[i].setAttribute("cx", d.x); n[i].setAttribute("cy", d.y); n[i].setAttribute("r", 2); }) .style("fill", "teal")
setAttribute with loop
const data = d3.range(200).map(() => ({ cx: Math.random() * 300, cy: Math.random() * 150, r: 2 })); const svg = d3.select("body") .append("svg"); const circles = svg.selectAll("circle") .data(data) .each((d, i, n) => { for(let key in d){ n[i].setAttribute(key, d[key]) } }) .style("fill", "teal")
Detached
const data = d3.range(200).map(() => ({ cx: Math.random() * 300, cy: Math.random() * 150, r: 2 })); const svg = d3.select("body") .append("svg") .remove(); const circles = svg.selectAll("circle") .data(data) .attr("cx", d=>d.x) .attr("cy", d=>d.y) .attr("r", 2) .style("fill", "teal"); d3.select("body") .append(() => svg.node())
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Default
each with setAttribute
setAttribute with loop
Detached
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
Multi attributes
Multiple Attributes
Multiple Attributes II
Multiple Attributes III
Comments
Confirm delete:
Do you really want to delete benchmark?