Comparing short array of numbers

Benchmark created on


Setup

const randomSmallNumber = (max) => Math.floor(Math.random() * max)

const slidesAfter = [];
const slidesBefore = [];

// random small array
for (let i; i < randomSmallNumber(10); i++) {
	slidesAfter.push(randomSmallNumber(30));
	slidesBefore.push(randomSmallNumber(30));
}

if (randomSmallNumber(1) === 1) {
	slidesBefore.push(randomSmallNumber(30));
}

const checkIfSlidesChanged = (before, after) => { 

        if (before.length !== after.length) return true;

        // if any slides don't match, then slides have changed
        if (after.find((slide, idx) => slide !== before[idx])) return true;

        return false;
    };

Test runner

Ready to run.

Testing in
TestOps/sec
JSON
JSON.stringify(slidesBefore) === JSON.stringify(slidesAfter);
ready
iteration
checkIfSlidesChanged(slidesBefore, slidesAfter);
ready

Revisions

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