Standard library / testing

testing.B.Elapsed()

Return accumulated measured duration, excluding paused intervals. Expected stdout: 'true\nPASS\n'. Run as a _test.go file using the Go test harness.

Formal Syntax & Structure

go syntaxgo
func (b *B) Elapsed() time.Duration

Return Value

time.Duration

Result of the operation described above.

Working Example

Example Snippetgo
package main
import (  "fmt"  "testing")
func TestReference(t *testing.T) {  r := testing.Benchmark(func(b *testing.B) {    if b.Elapsed() < 0 {      b.Fatal("negative elapsed")    }    for j := 0; j < b.N; j++ {    }  })  fmt.Println(r.N > 0)}
Go Reference