browser sorting

Benchmark created on


Setup

var wc = [0,4,10,0,7,3,4,7,10];
var hc = [5,4,2,10,0,3,1,2,6];
var test = [];
for(let i = 0; i < 10000; i++)
{
	var generated = [];
	for(let j = 0; j < 9; j++){
		generated.push(Math.random()*9|0);	
	} 
}

function stableSort(arr, compare)
    {
        const indices = new Map();
        arr.forEach( (v,i) => indices.set(v,i));
        return arr
            .sort((a, b) => compare(a, b) || indices.get(a) - indices.get(b));
    }

Test runner

Ready to run.

Testing in
TestOps/sec
native
for(let i = 0; i < test.length; i++)
{
	var g = test[i];
	g.sort((a,b)=>{
		return wc[a] - wc[b] + (hc[a] - hc[b])*10;
	})
}
ready
stable
for(let i = 0; i < test.length; i++)
{
	var g = test[i];
	stableSort(g, (a,b)=>{
		return wc[a] - wc[b] + (hc[a] - hc[b])*10;
	})
}
ready

Revisions

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