Created
June 13, 2012 06:08
-
-
Save gblache/2922169 to your computer and use it in GitHub Desktop.
Iterative vs Bulk add in Backbone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"> | |
<html> | |
<head> | |
<title>Backbone Collection Demo</title> | |
</head> | |
<script src="http://underscorejs.org/underscore.js" type="text/javascript"></script> | |
<script src="http://backbonejs.org/backbone.js" type="text/javascript"></script> | |
<script type="text/javascript"> | |
var collection = new Backbone.Collection(); | |
// Iterative add. | |
var start = new Date().getTime(); | |
_.times(1000, function() { | |
var model = new Backbone.Model({id: _.uniqueId()}); | |
collection.add(model); | |
}); | |
var finish = new Date().getTime(); | |
console.log(finish - start); | |
// Bulk add. | |
var start = new Date().getTime(); | |
var models = [] | |
_.times(1000, function() { | |
var model = new Backbone.Model({id: _.uniqueId()}); | |
models.push(model); | |
}); | |
collection.add(models); | |
var finish = new Date().getTime(); | |
console.log(finish - start); | |
</script> | |
<body></body> | |
</html> |
collection.add() will trigger model events. Does models.push() also trigger events?
@chcrist I don't think so.. models.push is array.push which is a native JS method that doesn't support events.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Console output