더북(TheBook)

테스트 함수가 실행되고 나면 pstats 내장 모듈에 들어 있는 Stats 클래스를 사용해 성능 통계를 추출할 수 있다. Stats에 들어 있는 여러 메서드를 사용해 관심 대상 프로파일 정보를 선택하고 정렬하는 방법을 조절하여 관심 있는 항목만 표시할 수 있다.

from pstats import Stats

stats = Stats(profiler)
stats.strip_dirs()
stats.sort_stats("cumulative")   # 누적 통계
stats.print_stats()