perf: wrote benchmark file for proxy script onRequest evaluation

This commit is contained in:
evilsocket 2018-01-11 01:34:39 +01:00
parent e543582257
commit 7d4a4521f4
2 changed files with 51 additions and 11 deletions

View file

@ -0,0 +1,37 @@
package modules
import (
"net/http"
"testing"
"github.com/evilsocket/bettercap-ng/log"
"github.com/evilsocket/bettercap-ng/session"
)
func getScript(src string) *HttpProxyScript {
sess := session.Session{}
sess.Env = session.NewEnvironment(&sess)
err, script := LoadProxyScriptSource("", src, &sess)
if err != nil {
log.Fatal("%s", err)
}
return script
}
func getRequest() *http.Request {
req, err := http.NewRequest("GET", "http://www.google.com/", nil)
if err != nil {
log.Fatal("%s", err)
}
return req
}
func BenchmarkOnRequest(b *testing.B) {
script := getScript("function onRequest(req,res){}")
req := getRequest()
for n := 0; n < b.N; n++ {
script.OnRequest(req)
}
}