Skip to content

Instantly share code, notes, and snippets.

@BenLubar
Created September 26, 2018 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenLubar/82a0b50c484c900929afdc2558dfbc9d to your computer and use it in GitHub Desktop.
Save BenLubar/82a0b50c484c900929afdc2558dfbc9d to your computer and use it in GitHub Desktop.
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())
}
"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