전체 코드를 실행해야하는 시간을 표시하려면 부스트 auto_cpu_timer
을 사용하고 싶습니다. 또한 progress_display
을 사용하여 루프의 진행 상황을보고 싶습니다.boost auto_cpu_timer와 progress_display를 동시에 사용하는 방법은 무엇입니까?
부스트는 두 개의 타이머 클래스를 가지고 있기 때문에 네임 스페이스에 문제가있는 것 같습니다. 여기서 progress_display
은 더 이상 사용되지 않는 라이브러리입니다.
http://www.boost.org/doc/libs/1_51_0/libs/timer/doc/index.html
그럼에도 불구하고,이를 달성하는 방법은 무엇입니까? 다음 예제는 내가하려고하는 것을 보여줍니다. AUTO
또는 PROG
을 사용하면 문제가 없지만 둘 다 함께 오류 메시지가 표시됩니다.
홈페이지 :는 g++ -lboost_timer main.cc -o time
#define AUTO
#define PROG
#ifdef PROG
#include <boost/progress.hpp>
#endif //---- PROG -----
#ifdef AUTO
#include <boost/timer/timer.hpp>
#endif //---- AUTO -----
#include <cmath>
int main()
{
#ifdef AUTO
boost::timer::auto_cpu_timer t;
#endif //---- AUTO -----
long loops = 100000000;
#ifdef PROG
boost::progress_display pd(loops);
#endif //---- PROG -----
//long loop to burn some time
for (long i = 0; i < loops; ++i)
{
std::sqrt(123.456L);
#ifdef PROG
++pd;
#endif //---- PROG -----
}
return 0;
}
오류 로그 컴파일 : 당신이 boost/progress.hpp
포함하면
/usr/include/boost/timer/timer.hpp:38:1: error: ‘namespace boost::timer { }’ redeclared as different kind of symbol
/usr/include/boost/timer.hpp:45:1: error: previous declaration of ‘class boost::timer’
/usr/include/boost/timer/timer.hpp: In member function ‘std::string boost::timer::cpu_timer::format(short int, const std::string&) const’:
/usr/include/boost/timer/timer.hpp:74:34: error: ‘format’ is not a member of ‘boost::timer’
/usr/include/boost/timer/timer.hpp: In member function ‘std::string boost::timer::cpu_timer::format(short int) const’:
/usr/include/boost/timer/timer.hpp:76:34: error: ‘format’ is not a member of ‘boost::timer’
main.cc: In function ‘int main()’:
main.cc:17:2: error: ‘auto_cpu_timer’ is not a member of ‘boost::timer’
main.cc:17:31: error: expected ‘;’ before ‘t’
우수! –
문제는 여전히 1.58에 있습니다. 부스트가 의도 한 동작입니까? – stfn
나는 잘 모르겠다. 부스트 녀석에게 무엇이 문제인지 물어봐야한다. – BigBoss