Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Generate random string
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36
Browser:
Chrome 128
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Test gen1
2377419.0 Ops/sec
Test gen2
3494086.8 Ops/sec
Script Preparation code:
function gen1() { return Math.random().toString(36).slice(2) } class EntropyPool { #entropy; #index constructor(poolSize = 1024) { this.#entropy = new Uint32Array(poolSize) this.#index = 0 crypto.getRandomValues(this.#entropy) } next() { const value = this.#entropy[this.#index++] if (this.#index === this.#entropy.length) { crypto.getRandomValues(this.#entropy) this.#index = 0 } return value } } const pool = new EntropyPool() function random() { return pool.next() / 4294967295 } const lowercase = 'abcdefghijklmnopqrstuvwxyz'; const uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; const digits = '0123456789'; const charset = `${lowercase}${uppercase}${digits}`; function gen2() { let result = ''; for (let i = 0; i < length; i++) { const id = randomInt([0, charset.length - 1]); result += charset[id]; } return result; }
Tests:
Test gen1
gen1()
Test gen2
gen2()