Memory check - Mtrace vs Valgrind (how long does it take)
Mtrace vs Valgrind
mtrace와 valgrind 둘 중 어느것이 memory 오류 검출 시 걸리는 시간을 비교했습니다.
테스트 code 1.
(mtrace 사용 시 주석 해제 후 재빌드)#include <stdio.h> #include <stdlib.h> //#include <mcheck.h> int main() { char *test; for(int i=0; i<10000; i++ ) { //mtrace(); test = malloc(10); free(test); //muntrace(); } printf("hello world\n"); return 0; }
속도 비교
일반 실행-bash-4.2$ time ./hello hello world real 0m0.002s user 0m0.000s sys 0m0.002s
mtrace 사용 시
-bash-4.2$ time ./hello hello world real 0m0.234s user 0m0.039s sys 0m0.188s
valgrind 사용 시
-bash-4.2$ time valgrind --leak-check=full ./hello ==15079== Memcheck, a memory error detector ==15079== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. ==15079== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info ==15079== Command: ./hello ==15079== hello world ==15079== ==15079== HEAP SUMMARY: ==15079== in use at exit: 0 bytes in 0 blocks ==15079== total heap usage: 10,000 allocs, 10,000 frees, 100,000 bytes allocated ==15079== ==15079== All heap blocks were freed -- no leaks are possible ==15079== ==15079== For counts of detected and suppressed errors, rerun with: -v ==15079== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2) real 0m0.335s user 0m0.314s sys 0m0.021s
테스트 코드2.
(mtrace 사용 시 주석 해제 후 재빌드)#include <stdio.h> #include <stdlib.h> //#include <mcheck.h> int main() { char *test; for(int i=0; i<10000; i++ ) { for(int j=0; j<100; j++) { //mtrace(); test = malloc(10); free(test); //muntrace(); } } printf("hello world\n"); return 0; }
속도 비교
일반 실행-bash-4.2$ time ./hello hello world real 0m0.029s user 0m0.029s sys 0m0.001s
mtrace 사용 시
-bash-4.2$ time ./hello hello world real 0m27.613s user 0m3.842s sys 0m23.636s
valginrd 사용 시
-bash-4.2$ time valgrind ./hello ==24091== Memcheck, a memory error detector ==24091== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. ==24091== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info ==24091== Command: ./hello ==24091== hello world ==24091== ==24091== HEAP SUMMARY: ==24091== in use at exit: 0 bytes in 0 blocks ==24091== total heap usage: 1,000,000 allocs, 1,000,000 frees, 10,000,000 bytes allocated ==24091== ==24091== All heap blocks were freed -- no leaks are possible ==24091== ==24091== For counts of detected and suppressed errors, rerun with: -v ==24091== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2) real 0m3.124s user 0m3.023s sys 0m0.094s
결론
mtrace가 code상에 들어가서 빠를것이라는 예상과 다르게 코드 복잡도가 올라갈수록 valgrind가 빠르게 동작했다.
댓글
댓글 쓰기