Standard library / testing

testing.B.SetParallelism()

Set worker count multiplier relative to GOMAXPROCS for RunParallel; values below one are ignored. Expected stdout: 'true\nPASS\n'. Run as a _test.go file using the Go test harness.

Formal Syntax & Structure

go syntaxgo
func (b *B) SetParallelism(p int)

Parameters & Attributes

NameTypeDescription
pintParallelism multiplier.

Working Example

Example Snippetgo
package main
import (  "fmt"  "testing")
func TestReference(t *testing.T) {  r := testing.Benchmark(func(b *testing.B) {    b.SetParallelism(2)    b.RunParallel(func(pb *testing.PB) {      for pb.Next() {      }    })  })  fmt.Println(r.N > 0)}
Go Reference