Deleting certain items from huge object

JavaScript performance comparison

Test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 
<script>
Benchmark.prototype.setup = function() {
    var Activity = {},
        count = 3000000;
    for (var i = 0; i < count; i++){
        Activity [i] = {
            commentCount: (i%50),
            likeCount: (i%40)
        };
    }
};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Pure js
var obj;
for (var field in Activity) {
    if (Activity.hasOwnProperty(field)) {
        obj = Activity[field];
        if (obj.commentCount === 0 && obj.likeCount === 0) {
            delete Activity[field];
        }
    }
}
pending…
jQuery each
$.each(Activity, function(field, val){
    if (val.commentCount === 0 && val.likeCount === 0) {
        delete Activity[field];
    }
});
pending…
jquery map (object)
Activity = $.map(Activity, function(val, key){
    if (val.commentCount === 0 && val.likeCount === 0) {
        return null;
    }
});
pending…
jQuery map (array)
var arrActivity = $.makeArray(Activity);
Activity = $.map(arrActivity, function(val, key){
    if (val.commentCount === 0 && val.likeCount === 0) {
        return null;
    }
});
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment