for-in versus Object.keys(..).forEach(..) (v15)

Revision 15 of this benchmark created on


Description

Testing if the perf hit for Object.keys(..).forEach(..) is enough to matter as compared to for-in.

Add quicker version of for-in without hasOwnProperty guard

Preparation HTML

<script src="//code.jquery.com/jquery-git2.min.js"></script>

Setup

function iterate1() {
       var ret = "";
       for (var i in obj) {
          if (obj.hasOwnProperty(i)) {
            ret += obj[i];
          }
       }
       return ret;
    }
    
    function iterate2() {
       var ret = "";
       Object.keys(obj).forEach(function(key){
          ret += obj[key];
       });
       return ret;
    }
    
    function iterate3() {
       var ret = "";
       for(var key in obj) {
          ret += obj[key];
       }
       return ret;
    }
    
    var tmp;
    var obj = {
        background_color: "#cccccc",
        custom_icon_data: "{}",
        default_folder_id: 1,
        dial_columns: 4,
        dial_width: 70,
        drag_and_drop: "true",
        enable_sync: "false",
        folder_color: "#888888",
        force_http: "true",
        show_advanced: "false",
        show_folder_list: "true",
        show_new_entry: "true",
        show_options_gear: "true",
        show_subfolder_icons: "true",
        thumbnailing_service: "http://immediatenet.com/t/l3?Size=1280x1024&URL=[URL]"
    };

Teardown


    tmp = "";
  

Test runner

Ready to run.

Testing in
TestOps/sec
for-in
tmp += iterate1();
ready
Object.keys(..).forEach(..)
tmp += iterate2();
ready
for-in (no ownproperty)
tmp += iterate3();
ready

Revisions

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