We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
benchmark_test.go
package gocoroutine import ( // "fmt" "sync" "testing" ) var k int = 0 var m int = 0 func msgProc_benchmark(fc FlowControl) { //fmt.Println("msg 1") fc.Yield(dbProc_benchmark) } func dbProc_benchmark(fc FlowControl) { //fmt.Println("db 1") // msgid := fc.Params().(int) k++ } func recvProc_benchmark(sch *Scheduler) { for i := 0; i < 100000; i++ { sch.AddTask(msgProc_benchmark, i) } } func TestBenchmark(t *testing.T) { sch := NewScheduler() sch.Start() recvProc_benchmark(sch) sch.Exit() println("final k:\n", k) } func traditionalLogic(wg *sync.WaitGroup) { wg.Add(1) m++ go func() { wg.Done() }() } // go test -bench=Benchmark -cpuprofile=cprof func TestTraditional(t *testing.T) { var wg sync.WaitGroup for i := 0; i < 100000; i++ { traditionalLogic(&wg) } wg.Wait() println("final m:\n", m) }
Scheduler 并不是单线程执行存在并发问题,执行结果为 99109 与 10000不符合
=== RUN TestBenchmark final k: 99096 --- PASS: TestBenchmark (0.17s) === RUN TestTraditional final m: 100000 --- PASS: TestTraditional (0.02s) PASS
The text was updated successfully, but these errors were encountered:
No branches or pull requests
benchmark_test.go
Scheduler 并不是单线程执行存在并发问题,执行结果为 99109 与 10000不符合
The text was updated successfully, but these errors were encountered: