Created
April 4, 2020 19:03
-
-
Save peter-leonov/c1672f3b9406b27f8297e2c73b75ed71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { openSync, readSync } = require('fs') | |
const DEV_RANDOM = openSync('/dev/random') | |
function getVeryRandomString(length) { | |
const buf = Buffer.alloc(length) | |
readSync(DEV_RANDOM, buf, 0, length) | |
return buf.toString() | |
} | |
const randInt = (from, to) => Math.ceil(from + Math.random() * to) | |
const urls = [] | |
for (let i = 0; i < 100_000; i++) { | |
urls.push('https://' + getVeryRandomString(randInt(15, 250)), i) | |
} | |
const queris = [] | |
for (let i = 0; i < 10_000; i++) { | |
queris.push(urls[randInt(0, urls.length)]) | |
} | |
let map = new Map(urls.map((url, i) => [url, i])) | |
console.log(map.size) | |
let sum = 0 | |
for (let run = 0; run < 10; run++) { | |
console.time('run ' + run) | |
for (let i = 0; i < queris.length; i++) { | |
sum += map.get(queris[i]) | |
} | |
console.timeEnd('run ' + run) | |
} | |
console.log('sum = ', sum) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment