Skip to content

Instantly share code, notes, and snippets.

@explunit
Created September 2, 2013 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save explunit/6413685 to your computer and use it in GitHub Desktop.
Save explunit/6413685 to your computer and use it in GitHub Desktop.
D3 browser memory usage test

D3 browser memory usage test

<!DOCTYPE html>
<meta http-equiv="X-UA-Compatible" content="IE=9">
<html>
<body>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script type="text/javascript">
var svg = d3.select("body").append("svg").attr( {width: 800, height: 800 });
var data = new Array(1000);
function randomizeData() {
for (var i = data.length - 1; i >= 0; i--) {
data[i] = { id: Math.random(), x: Math.random()*800, y: Math.random()*800 }
};
}
function update() {
randomizeData();
var circles = svg.selectAll("circle")
.data(data, function(d) { return d.id; } );
circles.exit().remove();
circles.enter().append("circle")
.attr("id", function(d) { return d.id; })
.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; })
.attr( { r: 5, fill: 'blue' })
.on("mouseenter", function(d) { console.log('mouse enter') });
}
setInterval(update, 1000);
</script>
</body>
</html>
@webxl
Copy link

webxl commented Mar 21, 2014

Thanks. Chrome peaks at about 45 MB running this and then sawtooths. IE11 got to 500 MB before the browser treated the site as being unresponsive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment