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
<script type="module">
const {cloneDeep} = await import ("https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.min.js");
window.cloneDeep = cloneDeep;
</script>const MyObject = {
description: 'Creates a deep copy of source, which should be an object or an array.',
myNumber: 123456789,
myBoolean: true,
jayson: {
stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....',
parse: 'JSON.parse() method parses a JSON string...'
}
};
///////////////////////////////////////////////////////////////////
class ObjectUtils {
static clone(obj) {
let clone
if (typeof obj !== 'object') {
return obj
}
if (!obj) {
return obj
}
if (Array.isArray(obj)) {
clone = []
for (let i = 0; i < obj.length; i += 1) {
clone[i] = ObjectUtils.clone(obj[i])
}
return clone
}
clone = {}
Object.keys(obj).forEach((key) => {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
clone[key] = ObjectUtils.clone(obj[key])
}
})
return clone
}
}
Ready to run.
| Test | Ops/sec | |
|---|---|---|
| JSON.parse(JSON.stringify(MyObject)) | | ready |
| cloneDeep(MyObject) | | ready |
| ObjectUtils.clone(MyObject) | | ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.