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

Revision 8 of this benchmark created on


Description

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

Preparation HTML

<script>



</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;
    }
    
    var tmp;
    var obj = {
        background_color: "#cccccc",
        custom_icon_data: "{}",
        default_folder_id: 1,
        dial_columns: 6,
        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

Revisions

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