github.com/AlexandreChamard/go-threadpool@v1.0.0/threadPool_test.go (about) 1 package threadpool 2 3 import ( 4 "fmt" 5 "testing" 6 "time" 7 8 . "github.com/AlexandreChamard/go-functor" 9 ) 10 11 func TestThreadPool(t *testing.T) { 12 tp := NewThreadPool(ThreadPoolConfig{ 13 PoolSize: 100, 14 EnableLog: true, 15 }) 16 17 f := func(i int) { 18 time.Sleep(100 * time.Millisecond) 19 // fmt.Println("coucou", i) 20 } 21 22 for n := 0; n < 100; n++ { 23 tp.SubmitPriority(MakeFunctor1_0(f, n), n/10) 24 } 25 26 tp.Stop() 27 tp.Wait() 28 } 29 30 func BenchmarkThreadPool(b *testing.B) { 31 b.Log("Start benchmark") 32 33 tp := NewThreadPool(ThreadPoolConfig{ 34 PoolSize: 1, 35 EnableLog: true, 36 }) 37 38 f := func(i int) { fmt.Println("coucou", i) } 39 40 for n := 0; n < 100; n++ { 41 tp.SubmitPriority(MakeFunctor1_0(f, n), n/10) 42 } 43 44 // time.Sleep(1 * time.Second) 45 46 tp.Stop() 47 tp.Wait() 48 }