mirror of
https://gitee.com/johng/gf
synced 2026-06-07 10:22:11 +08:00
gf/beego/gin性能测试对比
This commit is contained in:
@ -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()
|
||||
|
||||
37
geg/net/ghttp/performance/client.go
Normal file
37
geg/net/ghttp/performance/client.go
Normal 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())
|
||||
}
|
||||
15
geg/net/ghttp/performance/gf/dynamic.go
Normal file
15
geg/net/ghttp/performance/gf/dynamic.go
Normal 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()
|
||||
}
|
||||
15
geg/net/ghttp/performance/gf/static.go
Normal file
15
geg/net/ghttp/performance/gf/static.go
Normal 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()
|
||||
}
|
||||
@ -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()
|
||||
}
|
||||
Reference in New Issue
Block a user