Sorting Performance (v6)

Revision 6 of this benchmark created on


Description

Checking if the inbuilt .sort() is faster than a our own sort.

Setup

const letterList = ['g', 'j', 'b', 'p', 'y', 'i', 'm', 'p', 'v', 'l', 'y', 'a', 'a', 'r', 'q', 'x', 'k', 'z', 'a', 'h', 'e', 'c', 'i', 'w', 't', 's', 'k', 'b', 'u', 'c', 't', 'a', 'h', 'w', 'w', 's', 'z', 'e', 'f', 'r', 'p', 'w', 'c', 'l', 'e', 'z', 'x', 'l', 's', 'v', 's', 'h', 'x', 'k', 'b', 'o', 'a', 'n', 'g', 'h', 'u', 'g', 'r', 'p', 'a', 'w', 's', 'g', 'k', 'i', 'm', 'n', 'z', 'o', 'h', 'm', 'h', 'b', 'g', 'x', 'k', 'h', 'e', 's', 'l', 'v', 't', 'e', 'j', 'q', 's', 'y', 'h', 'g', 'c', 'o', 'f', 't', 'h', 's'];

Test runner

Ready to run.

Testing in
TestOps/sec
Function sort
console.log(letterList.slice().sort((a, b) => a.localeCompare(b)));

ready
Function expanded sort
console.log(letterList.slice().sort((a, b) => {
    if (a < b) return -1;
    if (a > b) return 1;
    return 0;
}));
ready
Inbuilt sort
console.log(letterList.sort())
ready

Revisions

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