fix tests
This commit is contained in:
parent
e548849f88
commit
13cb83b7a7
@ -132,9 +132,8 @@ func BenchmarkRouterLookup(b *testing.B) {
|
|||||||
path := "/"
|
path := "/"
|
||||||
params := &routers.Params{}
|
params := &routers.Params{}
|
||||||
|
|
||||||
b.ResetTimer()
|
for b.Loop() {
|
||||||
for i := 0; i < b.N; i++ {
|
_, _, _, _ = luaRouter.GetRouteInfo(method, path, params)
|
||||||
_, _, _, _, _ = luaRouter.GetRouteInfo(method, path, params)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,13 +145,12 @@ func BenchmarkSimpleLuaExecution(b *testing.B) {
|
|||||||
method := "GET"
|
method := "GET"
|
||||||
path := "/"
|
path := "/"
|
||||||
params := &routers.Params{}
|
params := &routers.Params{}
|
||||||
_, bytecode, scriptPath, _, _ := luaRouter.GetRouteInfo(method, path, params)
|
bytecode, scriptPath, _, _ := luaRouter.GetRouteInfo(method, path, params)
|
||||||
|
|
||||||
ctx := runner.NewContext()
|
ctx := runner.NewContext()
|
||||||
defer ctx.Release()
|
defer ctx.Release()
|
||||||
|
|
||||||
b.ResetTimer()
|
for b.Loop() {
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
_, _ = luaRunner.Run(bytecode, ctx, scriptPath)
|
_, _ = luaRunner.Run(bytecode, ctx, scriptPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -165,13 +163,12 @@ func BenchmarkComplexLuaExecution(b *testing.B) {
|
|||||||
method := "GET"
|
method := "GET"
|
||||||
path := "/complex"
|
path := "/complex"
|
||||||
params := &routers.Params{}
|
params := &routers.Params{}
|
||||||
_, bytecode, scriptPath, _, _ := luaRouter.GetRouteInfo(method, path, params)
|
bytecode, scriptPath, _, _ := luaRouter.GetRouteInfo(method, path, params)
|
||||||
|
|
||||||
ctx := runner.NewContext()
|
ctx := runner.NewContext()
|
||||||
defer ctx.Release()
|
defer ctx.Release()
|
||||||
|
|
||||||
b.ResetTimer()
|
for b.Loop() {
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
_, _ = luaRunner.Run(bytecode, ctx, scriptPath)
|
_, _ = luaRunner.Run(bytecode, ctx, scriptPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -185,10 +182,9 @@ func BenchmarkGetEndpoint(b *testing.B) {
|
|||||||
path := "/"
|
path := "/"
|
||||||
params := &routers.Params{}
|
params := &routers.Params{}
|
||||||
|
|
||||||
b.ResetTimer()
|
for b.Loop() {
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
// Route lookup
|
// Route lookup
|
||||||
_, bytecode, scriptPath, _, _ := luaRouter.GetRouteInfo(method, path, params)
|
bytecode, scriptPath, _, _ := luaRouter.GetRouteInfo(method, path, params)
|
||||||
|
|
||||||
// Context setup
|
// Context setup
|
||||||
ctx := runner.NewContext()
|
ctx := runner.NewContext()
|
||||||
@ -210,10 +206,9 @@ func BenchmarkPostEndpoint(b *testing.B) {
|
|||||||
path := "/"
|
path := "/"
|
||||||
params := &routers.Params{}
|
params := &routers.Params{}
|
||||||
|
|
||||||
b.ResetTimer()
|
for b.Loop() {
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
// Route lookup
|
// Route lookup
|
||||||
_, bytecode, scriptPath, _, _ := luaRouter.GetRouteInfo(method, path, params)
|
bytecode, scriptPath, _, _ := luaRouter.GetRouteInfo(method, path, params)
|
||||||
|
|
||||||
// Context setup with form data
|
// Context setup with form data
|
||||||
ctx := runner.NewContext()
|
ctx := runner.NewContext()
|
||||||
@ -237,7 +232,7 @@ func BenchmarkConcurrentExecution(b *testing.B) {
|
|||||||
method := "GET"
|
method := "GET"
|
||||||
path := "/"
|
path := "/"
|
||||||
params := &routers.Params{}
|
params := &routers.Params{}
|
||||||
_, bytecode, scriptPath, _, _ := luaRouter.GetRouteInfo(method, path, params)
|
bytecode, scriptPath, _, _ := luaRouter.GetRouteInfo(method, path, params)
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
b.RunParallel(func(pb *testing.PB) {
|
b.RunParallel(func(pb *testing.PB) {
|
||||||
@ -257,7 +252,7 @@ func BenchmarkConcurrentComplexExecution(b *testing.B) {
|
|||||||
method := "GET"
|
method := "GET"
|
||||||
path := "/complex"
|
path := "/complex"
|
||||||
params := &routers.Params{}
|
params := &routers.Params{}
|
||||||
_, bytecode, scriptPath, _, _ := luaRouter.GetRouteInfo(method, path, params)
|
bytecode, scriptPath, _, _ := luaRouter.GetRouteInfo(method, path, params)
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
b.RunParallel(func(pb *testing.PB) {
|
b.RunParallel(func(pb *testing.PB) {
|
||||||
@ -277,23 +272,12 @@ func BenchmarkMiddlewareExecution(b *testing.B) {
|
|||||||
method := "GET"
|
method := "GET"
|
||||||
path := "/api"
|
path := "/api"
|
||||||
params := &routers.Params{}
|
params := &routers.Params{}
|
||||||
middlewareBytecode, bytecode, scriptPath, _, _ := luaRouter.GetRouteInfo(method, path, params)
|
bytecode, scriptPath, _, _ := luaRouter.GetRouteInfo(method, path, params)
|
||||||
|
|
||||||
b.ResetTimer()
|
for b.Loop() {
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
ctx := runner.NewContext()
|
ctx := runner.NewContext()
|
||||||
|
|
||||||
// Execute middleware chain
|
// Execute combined middleware + handler
|
||||||
for _, mwBytecode := range middlewareBytecode {
|
|
||||||
if len(mwBytecode) > 0 {
|
|
||||||
response, _ := luaRunner.Run(mwBytecode, ctx, "middleware")
|
|
||||||
if response != nil {
|
|
||||||
runner.ReleaseResponse(response)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute handler
|
|
||||||
response, _ := luaRunner.Run(bytecode, ctx, scriptPath)
|
response, _ := luaRunner.Run(bytecode, ctx, scriptPath)
|
||||||
if response != nil {
|
if response != nil {
|
||||||
runner.ReleaseResponse(response)
|
runner.ReleaseResponse(response)
|
||||||
@ -314,8 +298,7 @@ func BenchmarkRouteCompilation(b *testing.B) {
|
|||||||
routesDir := filepath.Join(tempDir, "routes")
|
routesDir := filepath.Join(tempDir, "routes")
|
||||||
os.MkdirAll(routesDir, 0755)
|
os.MkdirAll(routesDir, 0755)
|
||||||
|
|
||||||
b.ResetTimer()
|
for b.Loop() {
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
os.RemoveAll(routesDir)
|
os.RemoveAll(routesDir)
|
||||||
os.MkdirAll(routesDir, 0755)
|
os.MkdirAll(routesDir, 0755)
|
||||||
@ -329,7 +312,7 @@ func BenchmarkRouteCompilation(b *testing.B) {
|
|||||||
|
|
||||||
// BenchmarkContextCreation measures the cost of creating execution contexts
|
// BenchmarkContextCreation measures the cost of creating execution contexts
|
||||||
func BenchmarkContextCreation(b *testing.B) {
|
func BenchmarkContextCreation(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
ctx := runner.NewContext()
|
ctx := runner.NewContext()
|
||||||
ctx.Release()
|
ctx.Release()
|
||||||
}
|
}
|
||||||
@ -360,10 +343,9 @@ func BenchmarkRunnerExecute(b *testing.B) {
|
|||||||
method := "GET"
|
method := "GET"
|
||||||
path := "/"
|
path := "/"
|
||||||
params := &routers.Params{}
|
params := &routers.Params{}
|
||||||
_, bytecode, scriptPath, _ := luaRouter.GetRouteInfo(method, path, params)
|
bytecode, scriptPath, _, _ := luaRouter.GetRouteInfo(method, path, params)
|
||||||
|
|
||||||
b.ResetTimer()
|
for b.Loop() {
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
ctx := runner.NewContext()
|
ctx := runner.NewContext()
|
||||||
_, _ = luaRunner.Execute(context.Background(), bytecode, ctx, scriptPath)
|
_, _ = luaRunner.Execute(context.Background(), bytecode, ctx, scriptPath)
|
||||||
ctx.Release()
|
ctx.Release()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user