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
Which method of applying default values is most efficient? Let's find out.
I should mention that the "or statement" method is fundamentally flawed. If, for example, param.var1 is set to false (and false is a valid parameter value), combined.var1 will be will incorrectly set to default.var1.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
var defaults = {
var1: true,
var2: 5,
var3: "foo"
};
var params = {
var1: false,
var3: "newvalue",
var4: 'rob'
}
var combined = {};
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
jQuery.extend() |
| ready |
Or Statement |
| ready |
typeOf |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.