Created
September 26, 2018 15:30
-
-
Save BenLubar/82a0b50c484c900929afdc2558dfbc9d 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
package main | |
import ( | |
"fmt" | |
"regexp" | |
"strings" | |
"time" | |
) | |
func main() { | |
for i := 0; i < 1000; i++ { | |
check(i) | |
} | |
} | |
func check(i int) { | |
// don't include compilation time as this is a static cost | |
re := regexp.MustCompile(fmt.Sprintf("^(?:a?){%[1]d}a{%[1]d}$", i)) | |
payload := strings.Repeat("a", i) | |
start := time.Now() | |
re.MatchString(payload) | |
fmt.Printf("%d\t%.9f\n", i, time.Since(start).Seconds()) | |
} |
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
"use strict"; | |
for (var i = 0; i < 1000; i++) { | |
check(i); | |
} | |
function check(i) { | |
// don't include compilation time as this is a static cost | |
var re = new RegExp("^(?:a?){" + i + "}a{" + i + "}$"); | |
var payload = new Array(i + 1).join("a"); | |
var start = process.hrtime(); | |
re.test(payload); | |
var diff = process.hrtime(start); | |
console.log(i + "\t" + (diff[0] + diff[1] * 1e-9).toFixed(9)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment