@
licoycn #44
同学,求 orm 使用者试玩我的 sqlw 一下给个体验反馈。
另外对于协程池,我这里有份 benchmark 请查收,包括标准库、ants 、字节的、我自己的库里带的,可以在自己机器上 linux 系统跑下试试不同的 cpu:
```sh
# sleep 0ns
ubuntu@ubuntu:~/test$ go test -v -bench=.
goos: linux
goarch: amd64
pkg: test
cpu: AMD Ryzen 7 5800H with Radeon Graphics
BenchmarkGo
BenchmarkGo-8 6322 178909 ns/op 16413 B/op 1025 allocs/op
BenchmarkBytedanceGopool
BenchmarkBytedanceGopool-8 2714 427975 ns/op 39506 B/op 2045 allocs/op
BenchmarkAnts
BenchmarkAnts-8 3746 315216 ns/op 16418 B/op 1025 allocs/op
BenchmarkMixedPool
BenchmarkMixedPool-8 4759 253604 ns/op 49168 B/op 3073 allocs/op
PASS
ok test 4.821s
# sleep 10ns
ubuntu@ubuntu:~/test$ go version
go version go1.18 linux/amd64
ubuntu@ubuntu:~/test$ go version
go version go1.18 linux/amd64
ubuntu@ubuntu:~/test$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.6 LTS
Release: 18.04
Codename: bionic
ubuntu@ubuntu:~/test$ go test -bench=. -v
goos: linux
goarch: amd64
pkg: test
cpu: AMD Ryzen 7 5800H with Radeon Graphics
BenchmarkGo
BenchmarkGo-8 4406 274001 ns/op 98522 B/op 2051 allocs/op
BenchmarkBytedanceGopool
BenchmarkBytedanceGopool-8 2404 486601 ns/op 55419 B/op 2212 allocs/op
BenchmarkAnts
BenchmarkAnts-8 3147 396720 ns/op 16437 B/op 1025 allocs/op
BenchmarkMixedPool
BenchmarkMixedPool-8 3530 346933 ns/op 131111 B/op 4097 allocs/op
PASS
ok test 5.021s
```
```golang
package test
import (
"sync"
"testing"
"time"
"
github.com/bytedance/gopkg/util/gopool"
"
github.com/lesismal/nbio/taskpool"
"
github.com/panjf2000/ants/v2"
)
const testLoopNum = 1024
const sleepTime = time.Nanosecond * 0
func BenchmarkGo(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
wg := sync.WaitGroup{}
wg.Add(testLoopNum)
for j := 0; j < testLoopNum; j++ {
go func() {
if sleepTime > 0 {
time.Sleep(sleepTime)
}
wg.Done()
}()
}
wg.Wait()
}
}
func BenchmarkBytedanceGopool(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
wg := sync.WaitGroup{}
wg.Add(testLoopNum)
for j := 0; j < testLoopNum; j++ {
gopool.Go(func() {
if sleepTime > 0 {
time.Sleep(sleepTime)
}
wg.Done()
})
}
wg.Wait()
}
}
func BenchmarkAnts(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
wg := sync.WaitGroup{}
wg.Add(testLoopNum)
for j := 0; j < testLoopNum; j++ {
ants.Submit(func() {
if sleepTime > 0 {
time.Sleep(sleepTime)
}
wg.Done()
})
}
wg.Wait()
}
}
func BenchmarkMixedPool(b *testing.B) {
p := taskpool.NewMixedPool(1024*4, 1, 1024)
defer p.Stop()
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
wg := sync.WaitGroup{}
wg.Add(testLoopNum)
for j := 0; j < testLoopNum; j++ {
p.Go(func() {
if sleepTime > 0 {
time.Sleep(sleepTime)
}
wg.Done()
})
}
wg.Wait()
}
}
```