sc vs encode vs ssc

Benchmark created on


Preparation HTML


Setup

function generateLargeObject(depth = 3, breadth = 5, arraySize = 10) {
    function createNestedObject(level) {
        if (level === 0) {
            return {
                data: Array.from({ length: arraySize }, (_, i) => `Item ${i}`),
                value: Math.random(),
            };
        }

        const obj = {};
        for (let i = 0; i < breadth; i++) {
            obj[`key${level}_${i}`] = createNestedObject(level - 1);
        }
        return obj;
    }

    return createNestedObject(depth);
}

const obj = generateLargeObject(7, 7, 20);

const encoder = new TextEncoder();

Test runner

Ready to run.

Testing in
TestOps/sec
sc
window.structuredClone(obj);
ready
encode
const jsonString = JSON.stringify(obj);
encoder.encode(jsonString).buffer;
ready
ssc
window.structuredClone(JSON.stringify(obj))
ready

Revisions

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