Hexa string comparison

Benchmark created on


Setup

const lowest = 'Z';
const highest = 'AAAAAAAAAA';

Test runner

Ready to run.

Testing in
TestOps/sec
With trim
const maxLength = Math.max(lowest.length, highest.length);


const lowestPadded = lowest.padStart(maxLength, '0');
const highestPadded = highest.padStart(maxLength, '0');


lowestPadded > highestPadded;
ready
With base conversion
function s2bigint(str, radix, charset) {
	let result = 0n;
	
	for (let i = 0; i < str.length; i++) {
    result += BigInt(charset.indexOf(str[i])) * radix ** BigInt(str.length -i - 1);
  }
  
  return result;
}

const strConverter = (str) => s2bigint(str, 26n, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ');


const bigLowest = strConverter(lowest);
const bigHighest = strConverter(highest);

bigLowest > bigHighest;
ready

Revisions

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