100 lines
1.7 KiB
Go
100 lines
1.7 KiB
Go
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
|
|
|
package procs_test
|
|
|
|
import (
|
|
"github.com/TeaOSLab/EdgeNode/internal/utils/procs"
|
|
"github.com/iwind/TeaGo/lists"
|
|
"runtime"
|
|
"sort"
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
func TestId_24(t *testing.T) {
|
|
runtime.GOMAXPROCS(24)
|
|
|
|
var procIds []int
|
|
var mu = &sync.Mutex{}
|
|
|
|
var countProcs = runtime.GOMAXPROCS(0)
|
|
var wg = &sync.WaitGroup{}
|
|
wg.Add(countProcs * 4096)
|
|
for i := 0; i < countProcs*4096; i++ {
|
|
go func() {
|
|
defer wg.Done()
|
|
|
|
mu.Lock()
|
|
var procId = procs.Id()
|
|
if !lists.ContainsInt(procIds, procId) {
|
|
procIds = append(procIds, procId)
|
|
}
|
|
mu.Unlock()
|
|
}()
|
|
}
|
|
wg.Wait()
|
|
|
|
sort.Ints(procIds)
|
|
t.Log(procIds)
|
|
}
|
|
|
|
func TestId_4(t *testing.T) {
|
|
runtime.GOMAXPROCS(4)
|
|
|
|
var procIds []int
|
|
var mu = &sync.Mutex{}
|
|
|
|
var countProcs = runtime.GOMAXPROCS(0)
|
|
var wg = &sync.WaitGroup{}
|
|
wg.Add(countProcs * 4096)
|
|
for i := 0; i < countProcs*4096; i++ {
|
|
go func() {
|
|
defer wg.Done()
|
|
|
|
mu.Lock()
|
|
var procId = procs.Id()
|
|
if !lists.ContainsInt(procIds, procId) {
|
|
procIds = append(procIds, procId)
|
|
}
|
|
mu.Unlock()
|
|
}()
|
|
}
|
|
wg.Wait()
|
|
|
|
sort.Ints(procIds)
|
|
t.Log(procIds)
|
|
}
|
|
|
|
func TestId_Auto(t *testing.T) {
|
|
var procIds []int
|
|
var mu = &sync.Mutex{}
|
|
|
|
var countProcs = runtime.GOMAXPROCS(0)
|
|
var wg = &sync.WaitGroup{}
|
|
wg.Add(countProcs * 4096)
|
|
for i := 0; i < countProcs*4096; i++ {
|
|
go func() {
|
|
defer wg.Done()
|
|
|
|
mu.Lock()
|
|
var procId = procs.Id()
|
|
if !lists.ContainsInt(procIds, procId) {
|
|
procIds = append(procIds, procId)
|
|
}
|
|
mu.Unlock()
|
|
}()
|
|
}
|
|
wg.Wait()
|
|
|
|
sort.Ints(procIds)
|
|
t.Log(procIds)
|
|
}
|
|
|
|
func BenchmarkId(b *testing.B) {
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
for pb.Next() {
|
|
_ = procs.Id()
|
|
}
|
|
})
|
|
}
|