mirror of
https://github.com/kataras/iris.git
synced 2025-12-17 09:57:01 +00:00
❤️ awesome and unique features for end-developers are coming...
total refactor of the hero and mvc packages, see README#Next (it's not completed yet) Former-commit-id: b85ae99cbfe5965ba919c1e15cf4989e787982c0
This commit is contained in:
32
_benchmarks/_internal/README.md
Normal file
32
_benchmarks/_internal/README.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# Benchmarks (internal)
|
||||
|
||||
Internal selected benchmarks between modified features across different versions.
|
||||
|
||||
* These benchmarks SHOULD run locally with a break of ~2 minutes between stress tests at the same machine, power plan and Turbo Boost set to ON
|
||||
* The system's `GOPATH` environment variable SHOULD match the [vNext/go.mod replace directive](vNext/go.mod#L5) one
|
||||
* A stress test may ran from a `name_test.go` file to measure _BUILD TIME_
|
||||
* each version executes: `go test -run=NONE --bench=. -count=5 --benchmem > name_test.txt`
|
||||
* the result will be presented through [benchstat](https://pkg.go.dev/golang.org/x/perf/cmd/benchstat) tool
|
||||
* _Or/and_ by firing [bombardier](https://github.com/codesenberg/bombardier/releases/tag/v1.2.4) _HTTP requests_ when it (the test) listens to an address
|
||||
* Each benchmark SHOULD contain a brief explanation of what it does.
|
||||
|
||||
## Dependency Injection
|
||||
|
||||
Measures handler factory time.
|
||||
|
||||
| Name | Ops | Ns/op | B/op | Allocs/op |
|
||||
|---------|:------|:--------|:--------|----|
|
||||
| vNext | 181726 | 6631 | 1544 | 17 |
|
||||
| v12.1.x | 96001 | 12604 | 976 | 26 |
|
||||
|
||||
It accepts a dynamic path parameter and a JSON request. It returns a JSON response. Fires 500000 requests with 125 concurrent connections.
|
||||
|
||||
```sh
|
||||
# di.go
|
||||
$ bombardier -c 125 -n 500000 --method="POST" --body-file=./request.json http://localhost:5000/42
|
||||
```
|
||||
|
||||
| Name | Throughput | Reqs/sec | Latency | Time To Complete |
|
||||
|---------|:-----------|:----------|:---------|----------------|
|
||||
| vNext | 46.51MB/s | 160480.74 | 777.33us | 3s |
|
||||
| v12.1.x | 32.43MB/s | 108839.19 | 1.14ms | 4s |
|
||||
1
_benchmarks/_internal/request.json
Normal file
1
_benchmarks/_internal/request.json
Normal file
@@ -0,0 +1 @@
|
||||
{"email":"my_email"}
|
||||
38
_benchmarks/_internal/v12.1.x/di.go
Normal file
38
_benchmarks/_internal/v12.1.x/di.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/kataras/iris/v12/hero"
|
||||
)
|
||||
|
||||
type (
|
||||
testInput struct {
|
||||
Email string `json:"email"`
|
||||
}
|
||||
|
||||
testOutput struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
)
|
||||
|
||||
func handler(id int, in testInput) testOutput {
|
||||
return testOutput{
|
||||
ID: id,
|
||||
Name: in.Email,
|
||||
}
|
||||
}
|
||||
|
||||
func dependency(ctx iris.Context) (in testInput, err error) {
|
||||
err = ctx.ReadJSON(&in)
|
||||
return
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
c := hero.New()
|
||||
c.Register(dependency)
|
||||
app.Post("/{id:int}", c.Handler(handler))
|
||||
app.Listen(":5000", iris.WithOptimizations)
|
||||
}
|
||||
15
_benchmarks/_internal/v12.1.x/di_test.go
Normal file
15
_benchmarks/_internal/v12.1.x/di_test.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/kataras/iris/v12/hero"
|
||||
)
|
||||
|
||||
func BenchmarkHero(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
c := hero.New()
|
||||
c.Register(dependency)
|
||||
_ = c.Handler(handler)
|
||||
}
|
||||
}
|
||||
BIN
_benchmarks/_internal/v12.1.x/di_test.txt
Normal file
BIN
_benchmarks/_internal/v12.1.x/di_test.txt
Normal file
Binary file not shown.
8
_benchmarks/_internal/v12.1.x/go.mod
Normal file
8
_benchmarks/_internal/v12.1.x/go.mod
Normal file
@@ -0,0 +1,8 @@
|
||||
module myoldapp
|
||||
|
||||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/kataras/iris/v12 v12.1.8
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
|
||||
)
|
||||
29
_benchmarks/_internal/vNext/di.go
Normal file
29
_benchmarks/_internal/vNext/di.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris/v12"
|
||||
)
|
||||
|
||||
type (
|
||||
testInput struct {
|
||||
Email string `json:"email"`
|
||||
}
|
||||
|
||||
testOutput struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
)
|
||||
|
||||
func handler(id int, in testInput) testOutput {
|
||||
return testOutput{
|
||||
ID: id,
|
||||
Name: in.Email,
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
app.HandleFunc(iris.MethodPost, "/{id:int}", handler)
|
||||
app.Listen(":5000", iris.WithOptimizations)
|
||||
}
|
||||
14
_benchmarks/_internal/vNext/di_test.go
Normal file
14
_benchmarks/_internal/vNext/di_test.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/kataras/iris/v12/hero"
|
||||
)
|
||||
|
||||
func BenchmarkHero(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
c := hero.New()
|
||||
_ = c.Handler(handler)
|
||||
}
|
||||
}
|
||||
BIN
_benchmarks/_internal/vNext/di_test.txt
Normal file
BIN
_benchmarks/_internal/vNext/di_test.txt
Normal file
Binary file not shown.
7
_benchmarks/_internal/vNext/go.mod
Normal file
7
_benchmarks/_internal/vNext/go.mod
Normal file
@@ -0,0 +1,7 @@
|
||||
module myapp
|
||||
|
||||
go 1.14
|
||||
|
||||
replace github.com/kataras/iris/v12 => C:/mygopath/src/github.com/kataras/iris
|
||||
|
||||
require github.com/kataras/iris/v12 v12.1.8
|
||||
@@ -12,7 +12,7 @@ func main() {
|
||||
mvc.New(app.Party("/api/values/{id}")).
|
||||
Handle(new(controllers.ValuesController))
|
||||
|
||||
app.Run(iris.Addr(":5000"))
|
||||
app.Listen(":5000")
|
||||
}
|
||||
|
||||
// +2MB/s faster than the previous implementation, 0.4MB/s difference from the raw handlers.
|
||||
|
||||
@@ -8,5 +8,5 @@ func main() {
|
||||
ctx.WriteString("value")
|
||||
})
|
||||
|
||||
app.Run(iris.Addr(":5000"))
|
||||
app.Listen(":5000")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user