Script Preparation code:
x
 
let s1MB = "0123456789".repeat(1000*100);
var strings1MB = Array.from(Array(20)).map(o=>s1MB + String.fromCharCode(32+~~(Math.random()*96)))
let s2MB = "0123456789".repeat(1000*200);
var strings2MB = Array.from(Array(20)).map(o=>s2MB + String.fromCharCode(32+~~(Math.random()*96)))
let s10MB = "0123456789".repeat(1000*1000);
var strings10MB = Array.from(Array(20)).map(o=>s10MB + String.fromCharCode(32+~~(Math.random()*96)))
function compare(a, b) {
    const lenA = a.length;
    const lenB = b.length;
    const minLen = lenA < lenB ? lenA : lenB;
    var i = 0;
    for (; i < minLen; ++i) {
        const ca = a.charCodeAt(i);
        const cb = b.charCodeAt(i);
        if (ca > cb)
            return 1;
        else if (ca < cb)
            return -1;
    }
    if (lenA === lenB)
        return 0;
    return lenA > lenB ? 1 : -1;
};
Tests:
  • 1MB string comparison

     
    const s1 = strings1MB[~~(strings1MB.length*Math.random())];
    const s2 = strings1MB[~~(strings1MB.length*Math.random())];
    const b = s1 === s2;
  • 2MB string comparison

     
    const s1 = strings2MB[~~(strings2MB.length*Math.random())];
    const s2 = strings2MB[~~(strings2MB.length*Math.random())];
    const b = s1 === s2;
  • 10MB string comparison

     
    const s1 = strings10MB[~~(strings10MB.length*Math.random())];
    const s2 = strings10MB[~~(strings10MB.length*Math.random())];
    const b = s1 === s2;
  • 1MB string comparison+

     
    const s1 = strings1MB[~~(strings1MB.length*Math.random())];
    const s2 = strings1MB[~~(strings1MB.length*Math.random())];
    const b = compare(s1,s2);
  • 2MB string comparison+

     
    const s1 = strings2MB[~~(strings2MB.length*Math.random())];
    const s2 = strings2MB[~~(strings2MB.length*Math.random())];
    const b = compare(s1,s2);
  • 10MB string comparison+

     
    const s1 = strings10MB[~~(strings10MB.length*Math.random())];
    const s2 = strings10MB[~~(strings10MB.length*Math.random())];
    const b = compare(s1,s2);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    1MB string comparison
    2MB string comparison
    10MB string comparison
    1MB string comparison+
    2MB string comparison+
    10MB string comparison+

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
Chrome 123 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
1MB string comparison 452040.8 Ops/sec
2MB string comparison 52613.8 Ops/sec
10MB string comparison 2013.2 Ops/sec
1MB string comparison+ 246.2 Ops/sec
2MB string comparison+ 113.9 Ops/sec
10MB string comparison+ 22.7 Ops/sec