gf/beego/gin性能测试对比

This commit is contained in:
John
2018-05-27 22:07:46 +08:00
parent 8a7232357d
commit b4711a587f
5 changed files with 83 additions and 12 deletions

View File

@ -477,9 +477,7 @@ func mapToStruct() {
}
func main() {
r, err := db.Table("user").Data([]map[string]interface{}{
map[string]interface{}{"name" : "john11111"},
}).Insert()
r, err := db.Table("user").Data(g.Map{"name" : "john11111"}).Insert()
fmt.Println(r)
fmt.Println(err)
//create()

View File

@ -0,0 +1,37 @@
package main
import (
"fmt"
"sync"
"gitee.com/johng/gf/g/os/gtime"
"gitee.com/johng/gf/g/net/ghttp"
"gitee.com/johng/gf/g/container/gtype"
)
func main() {
clientMax := 10
requestMax := 1000
failureNum := gtype.NewInt64()
successNum := gtype.NewInt64()
startTime := gtime.Millisecond()
wg := sync.WaitGroup{}
for i := 0; i < clientMax; i++ {
wg.Add(1)
go func(clientId int) {
for j := 0; j < requestMax; j++ {
if c, e := ghttp.Get("http://127.0.0.1/"); e == nil {
c.Close()
successNum.Add(1)
} else {
failureNum.Add(1)
}
}
wg.Done()
}(i)
}
wg.Wait()
fmt.Printf("time spent: %d ms, success:%d, failure: %d\n",
gtime.Millisecond() - startTime, successNum.Val(), failureNum.Val())
}

View File

@ -0,0 +1,15 @@
package main
import (
"gitee.com/johng/gf/g"
"gitee.com/johng/gf/g/net/ghttp"
)
func main() {
s := g.Server()
s.BindHandler("/dynamic/:name", func(r *ghttp.Request){
r.Response.Writeln(r.Get("name"))
})
s.SetPort(8199)
s.Run()
}

View File

@ -0,0 +1,15 @@
package main
import (
"gitee.com/johng/gf/g"
"gitee.com/johng/gf/g/net/ghttp"
)
func main() {
s := g.Server()
s.BindHandler("/", func(r *ghttp.Request){
r.Response.Writeln("哈喽世界!")
})
s.SetPort(8199)
s.Run()
}

View File

@ -1,16 +1,22 @@
package main
import (
"gitee.com/johng/gf/g"
"fmt"
"time"
"gitee.com/johng/gf/g"
"gitee.com/johng/gf/g/os/gproc"
)
func main() {
c := g.Config()
c.SetPath("/home/john/Workspace/Go/GOPATH/src/gitee.com/johng/gf/geg/os/gcfg")
c.SetFileName("redis.yml")
fmt.Println(c.Get("redis-cache"))
}
if !gproc.IsChild() {
go func() {
for {
fmt.Println("test")
time.Sleep(2 * time.Second)
}
}()
}
s := g.Server()
s.SetPort(9000)
s.Run()
}