Clone performance (v2)

Revision 2 of this benchmark created on


Preparation HTML

<script src="
https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js
"></script>

Setup

function clone(obj) {
    if (obj == null || typeof obj != "object") {
        return obj;
    }
    try {
        const temp = new obj.constructor();
        for(const key in obj){
            temp[key] = clone(obj[key]);
        }
        return temp;
    } catch (e) {
        return _.cloneDeep(obj);
    }
}

const data = {
    "id": "chatcmpl-8KoJwsI6naYRYgsJDx3zsjNIY2bo2",
    "object": "chat.completion",
    "created": 1699970684,
    "model": "gpt-4-1106-vision-preview",
    "usage": {
        "prompt_tokens": 805,
        "completion_tokens": 103,
        "total_tokens": 908
    },
    "choices": [
        {
            "message": {
                "role": "assistant",
                "content": "```\nbarcode,quantity,price\n2035958000000,4.00000000```"
            },
            "finish_details": {
                "type": "stop",
                "stop": "<|fim_suffix|>"
            },
            "index": 0
        }
    ]
}

data.self = data

Test runner

Ready to run.

Testing in
TestOps/sec
Basic
clone(data)
ready
Lodash
_.cloneDeep(data)
ready

Revisions

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