Skip to content

Commit

Permalink
update benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
lxzan committed Dec 14, 2023
1 parent 1fa1819 commit f2f9030
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 31 deletions.
62 changes: 32 additions & 30 deletions benchmark/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ const (
N = 13
)

func newJob(wg *sync.WaitGroup) func() {
return func() {
fib(N)
wg.Done()
}
}

func Benchmark_Fib(b *testing.B) {
for i := 0; i < b.N; i++ {
fib(N)
Expand All @@ -24,77 +31,72 @@ func Benchmark_StdGo(b *testing.B) {
for i := 0; i < b.N; i++ {
wg := &sync.WaitGroup{}
wg.Add(M)
job := newJob(wg)
for j := 0; j < M; j++ {
go func() {
fib(N)
wg.Done()
}()
go job()
}
wg.Wait()
}
}

func Benchmark_QueuesSingle(b *testing.B) {
q := queues.New(
queues.WithConcurrency(Concurrency),
queues.WithSharding(1),
)

for i := 0; i < b.N; i++ {
q := queues.New(
queues.WithConcurrency(Concurrency),
)
wg := &sync.WaitGroup{}
wg.Add(M)
job := newJob(wg)
for j := 0; j < M; j++ {
q.Push(func() {
fib(N)
wg.Done()
})
q.Push(job)
}
wg.Wait()
}
}

func Benchmark_QueuesMultiple(b *testing.B) {
q := queues.New(
queues.WithConcurrency(1),
queues.WithSharding(Concurrency),
)

for i := 0; i < b.N; i++ {
q := queues.New(
queues.WithConcurrency(1),
queues.WithSharding(Concurrency),
)
wg := &sync.WaitGroup{}
wg.Add(M)
job := newJob(wg)
for j := 0; j < M; j++ {
q.Push(func() {
fib(N)
wg.Done()
})
q.Push(job)
}
wg.Wait()
}
}

func Benchmark_Ants(b *testing.B) {
q, _ := ants.NewPool(Concurrency)
defer q.Release()

for i := 0; i < b.N; i++ {
q, _ := ants.NewPool(Concurrency)
wg := &sync.WaitGroup{}
wg.Add(M)
job := newJob(wg)
for j := 0; j < M; j++ {
q.Submit(func() {
fib(N)
wg.Done()
})
q.Submit(job)
}
wg.Wait()
q.Release()
}
}

func Benchmark_GoPool(b *testing.B) {
q := gopool.NewPool("", Concurrency, gopool.NewConfig())

for i := 0; i < b.N; i++ {
q := gopool.NewPool("", Concurrency, gopool.NewConfig())
wg := &sync.WaitGroup{}
wg.Add(M)
job := newJob(wg)
for j := 0; j < M; j++ {
q.Go(func() {
fib(N)
wg.Done()
})
q.Go(job)
}
wg.Wait()
}
Expand Down
2 changes: 1 addition & 1 deletion internal/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func (c *Queue[T]) Pop() (value T) {
c.tail = 0
}

c.stack.Push(ele.addr)
value = ele.Value
c.stack.Push(ele.addr)
*ele = c.template
return value
}
Expand Down

0 comments on commit f2f9030

Please sign in to comment.