Skip to content

Instantly share code, notes, and snippets.

@mfbx9da4
Created February 1, 2020 15:16
Show Gist options
  • Save mfbx9da4/8c8765ca955d842761fbf686750880cf to your computer and use it in GitHub Desktop.
Save mfbx9da4/8c8765ca955d842761fbf686750880cf to your computer and use it in GitHub Desktop.
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