Golang testing.AllocsPerRun() function example
package testing
Golang testing.AllocsPerRun() function usage example
package main
import (
"fmt"
"testing"
)
func main() {
runTests := func() {
fmt.Println("running tests")
}
allocs := testing.AllocsPerRun(10, runTests)
if allocs != 0 {
fmt.Printf("expected no allocs for tests, got %v", allocs)
}
}
Output :
running tests
running tests
running tests
running tests
running tests
running tests
running tests
running tests
running tests
running tests
running tests
expected no allocs for tests, got 3
Reference :
Advertisement
Something interesting
Tutorials
+9.4k Golang : Apply Histogram Equalization to color images
+35.1k Golang : Upload and download file to/from AWS S3
+10k CodeIgniter : Load different view for mobile devices
+16.6k Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file
+5.9k Golang : Detect variable or constant type
+8.3k Golang : Check if integer is power of four example
+36.4k Golang : Convert date or time stamp from string to time.Time type
+12.8k Golang : Listen and Serve on sub domain example
+13.7k Golang : Check if an integer is negative or positive
+15.3k Golang : How to get Unix file descriptor for console and file
+6k PageSpeed : Clear or flush cache on web server
+26.3k Golang : Calculate future date with time.Add() function