mardi 23 août 2016

Go-lang Testing, What is the meaning of Parallel Setting on Benchmark?

In http://ift.tt/1jrXBfW described that we can use testing.B.RunParallel() function to run benchmark in a parallel setting. I tried to write simple testing code:

func BenchmarkFunctionSome(b *testing.B) {

    for i := 0; i < b.N; i++ {
        SomeFunction()
    }
}

and then i changed it to use RunParallel()

func BenchmarkFunctionSome(b *testing.B) {

    b.RunParallel(func(pb *testing.PB) {
        for pb.Next() {
            SomeFunction()
        }
    })
}

And the one which used RunParallel() is slower than the first benchmark.

Actually what is the meaning of parallel setting in benchmarking? Why it became slower if i used RunParallel() ?

Aucun commentaire:

Enregistrer un commentaire