Created
February 1, 2020 15:16
-
-
Save mfbx9da4/8c8765ca955d842761fbf686750880cf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function time(fn) { | |
var s = performance.now() | |
fn() | |
return performance.now() - s | |
} | |
function average(array) { | |
return array.reduce((prev, cur) => prev + cur, 0) / array.length | |
} | |
async function fetchText() { | |
let res = await fetch( | |
'https://twitter.com/justsml/status/1221830342471868416', | |
) | |
return res.text() | |
} | |
async function main() { | |
const value = await fetchText() | |
const regex = /^[^@]+@[^@]{2,}\.[^@]{2,}$/ | |
const time1 = [] | |
const time2 = [] | |
var T = 10000 | |
for (let i = 0; i < T; i++) { | |
time1.push(time(() => regex.test(value))) | |
} | |
console.log('time1', average(time1)) | |
for (let i = 0; i < T; i++) { | |
time2.push(time(() => /^[^@]+@[^@]{2,}\.[^@]{2,}$/.test(value))) | |
} | |
console.log('time2', average(time2)) | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment