jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
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
Add Object.keys() + for loop version
function iterate1(obj) {
var ret = "";
for (var i in obj) {
if (obj.hasOwnProperty(i)) {
ret += obj[i];
}
}
return ret;
}
function iterate2(obj) {
var ret = "";
Object.keys(obj).forEach(function(key) {
ret += obj[key];
});
return ret;
}
function iterate3(obj) {
var ret = "";
for (var key in obj) {
ret += obj[key];
}
return ret;
}
function iterate4(obj) {
var ret = "",
keys = Object.keys(obj);
for (var i = 0, l = keys.length; i < l; i++) {
ret += obj[keys[i]];
}
return ret;
}
var tmp;
var objLg = {
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]",
a_background_color: "#cccccc",
a_custom_icon_data: "{}",
a_default_folder_id: 1,
a_dial_columns: 4,
a_dial_width: 70,
a_drag_and_drop: "true",
a_enable_sync: "false",
a_folder_color: "#888888",
a_force_http: "true",
a_show_advanced: "false",
a_show_folder_list: "true",
a_show_new_entry: "true",
a_show_options_gear: "true",
a_show_subfolder_icons: "true",
a_thumbnailing_service: "http://immediatenet.com/t/l3?Size=1280x1024&URL=[URL]"
};
var objMd = {
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]"
};
var objSm = {
background_color: "#cccccc",
custom_icon_data: "{}",
default_folder_id: 1,
dial_columns: 4,
drag_and_drop: "true",
};
var objOne = {
background_color: "#cccccc",
};
tmp = "";
Ready to run.
Test | Ops/sec | |
---|---|---|
Large — for-in |
| ready |
Large — Object.keys(..).forEach(..) |
| ready |
Large — for-in (no ownproperty) |
| ready |
Large — Object.keys(..) + for loop |
| ready |
Medium — for-in |
| ready |
Medium — Object.keys(..).forEach(..) |
| ready |
Medium — for-in (no ownproperty) |
| ready |
Medium — Object.keys(..) + for loop |
| ready |
Small — for-in |
| ready |
Small — Object.keys(..).forEach(..) |
| ready |
Small — for-in (no ownproperty) |
| ready |
Small — Object.keys(..) + for loop |
| ready |
Single — for-in |
| ready |
Single — Object.keys(..).forEach(..) |
| ready |
Single — for-in (no ownproperty) |
| ready |
Single — Object.keys(..) + for loop |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.