func TestParallelFunctions(t *testing.T) { t.Run("ParallelFunctions", func(t *testing.T) { t.Parallel() t.Run("Function1", func(t *testing.T) { t.Parallel() t.Logf("Running test function 1") }) t.Run("Function2", func(t *testing.T) { t.Parallel() t.Logf("Running test function 2") }) }) } func BenchmarkParallelFunctions(b *testing.B) { b.RunParallel(func(pb *testing.PB) { for pb.Next() { fmt.Printf("%s\n", string(rand.Intn(100))) } }) }
func BenchmarkFibonacci(b *testing.B) { for n := 0; n <= b.N; n++ { fib(n) } } func BenchmarkParallelFibonacci(b *testing.B) { b.RunParallel(func(pb *testing.PB) { for pb.Next() { fib(30) } }) } func fib(n int) int { if n <= 1 { return n } return fib(n-1) + fib(n-2) }In this example, two Fibonacci functions are tested to quantify their performance difference. The first function is the naive implementation of the Fibonacci sequence which uses recursion. The second implementation is a parallel implementation of the Fibonacci sequence. Package: testing.