idgen

Benchmark created on


Preparation HTML

<script>
function generateId(prefix, existingIds = [], length = 5, separator = "-") {
	const randomString = Math.random().toString(16);
	const newId = `${prefix}${separator}${randomString.slice(2, length + 2)}`;

	if (existingIds.includes(newId)) {
		return generateId(prefix, existingIds, length, separator);
	}

	return newId;
}

function generateId2() {
  return crypto.randomUUID();
}
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
random
generateId("abcdef")
ready
crypto
generateId2()
ready
random with existing
generateId("abcdef", ["sdaf", "fghdfghdf", "fghdfgjdfgj", "ghjkhgjkhgjk", "ghjfghkfghk", "ghkfghjfghj"])
ready

Revisions

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