PHpullh
학습 라이브러리/Go/벤치마크 분석

GO · 성능

벤치마크 분석

benchstat으로 벤치마크 결과를 통계적으로 비교합니다. 최적화 전후 성능을 객관적으로 평가합니다.

성능중급benchstatbenchmarkstatisticscomparison

핵심 설명

benchstat으로 벤치마크 결과를 통계적으로 비교합니다. 최적화 전후 성능을 객관적으로 평가합니다.

Go code

package main

import "fmt"

func main() {
	fmt.Println("=== 벤치마크 분석 워크플로우 ===")
	fmt.Println()
	fmt.Println("1. 벤치마크 실행 (최소 5회):")
	fmt.Println("  go test -bench=. -count=5 > old.txt")
	fmt.Println()
	fmt.Println("2. 코드 최적화 후 재실행:")
	fmt.Println("  go test -bench=. -count=5 > new.txt")
	fmt.Println()
	fmt.Println("3. 통계 비교:")
	fmt.Println("  benchstat old.txt new.txt")
	fmt.Println()
	fmt.Println("출력 예시:")
	fmt.Println("  name       old time/op  new time/op  delta")
	fmt.Println("  Process-8  1.50ms ± 2%  0.85ms ± 1%  -43.33%")
	fmt.Println()
	fmt.Println("4. 메모리 포함 분석:")
	fmt.Println("  go test -bench=. -benchmem -count=5 > result.txt")
	fmt.Println()
	fmt.Println("설치:")
	fmt.Println("  go install golang.org/x/perf/cmd/benchstat@latest")
}

학습 팁

-count=5 이상으로 여러 번 실행해야 통계적으로 유의미한 비교가 가능합니다. benchstat이 p-value를 계산합니다.

주의할 점

벤치마크를 1회만 실행하면 노이즈에 의한 오차가 클 수 있습니다. 최소 5회 실행하여 분산을 확인하세요.

자주 묻는 질문

벤치마크 분석란 무엇인가요?

benchstat 으로 벤치마크 결과를 통계적으로 비교합니다. 최적화 전후 성능을 객관적으로 평가합니다.

벤치마크 분석 학습 시 주의할 점은 무엇인가요?

벤치마크를 1회만 실행하면 노이즈에 의한 오차가 클 수 있습니다. 최소 5회 실행하여 분산을 확인하세요.