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 (useless if you can control your Object prototype!)
Add slower version with Object.hasOwnProperty (worst case for-in?)
<script>
</script>
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;
}
function iterate4() {
var ret = "";
for(var key in obj) {
if (Object.hasOwnProperty.call(obj, 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]"
};
tmp = "";
Ready to run.
Test | Ops/sec | |
---|---|---|
for-in |
| ready |
Object.keys(..).forEach(..) |
| ready |
for-in (no ownproperty) |
| ready |
for-in Object.ownproperty |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.