스트링 offset 파싱 속도 비교

다음과 같은.. 스트링이 있을때..

char *s = "10000001   1201712009430120094781202507512025075";

8,8,8,8,8,8,8 자리로 끊어서 읽고 싶은데..
sscanf는 공백을 무시고 읽어.. 원하는데로 동작되지 않음..
하여 찾다보니.. boost에 offset_separator 라는것이 있음..
테스트 하는 김에 속도 비교를 해봄..

sscanf의 경우.. (대략 88.637946초)

std::chrono::system_clock::time_point start = std::chrono::system_clock::now();
for(int i=0; i<100000000; i++) {
	char *s = "10000001   1201712009430120094781202507512025075";
	unsigned int eid, pid, n1, n2, n3, n4;
	int cnt = sscanf(s, "%8u%8u%8u%8u%8u%8u", &eid, &pid, &n1, &n2, &n3, &n4);
}
std::chrono::system_clock::time_point end = std::chrono::system_clock::now();
std::chrono::duration<double> sec = end - start;
printf("%f(sec)}", sec.count());

boost의 offset_separator (대략 72.378287초)

std::chrono::system_clock::time_point start = std::chrono::system_clock::now();
for(int i=0; i<100000000; i++) {
	std::string s = "10000001   1201712009430120094781202507512025075";

   int offsets[] = {8,8,8,8,8,8};
   boost::offset_separator f(offsets, offsets+6);
   boost::tokenizer<boost::offset_separator> tok(s,f);
   //for(boost::tokenizer<boost::offset_separator>::iterator beg=tok.begin(); beg!=tok.end();++beg){
	 //  std::cout << *beg << "\n";
  // }
   const size_t count = std::distance(tok.begin(), tok.end());
   //std::cout << count << "\n";
   boost::tokenizer<boost::offset_separator>::iterator it1 = tok.begin();
   //std::cout << *it1 << "\n";
   ++it1;
   //std::cout << *it1 << "\n";
   ++it1;
   //std::cout << *it1 << "\n";
   ++it1;
   //std::cout << *it1 << "\n";
   ++it1;
   //std::cout << *it1 << "\n";
   ++it1;
   //std::cout << *it1 << "\n";
}
std::chrono::system_clock::time_point end = std::chrono::system_clock::now();
std::chrono::duration<double> sec = end - start;
printf("%f(sec)}", sec.count());

역시.. 구글링을 해보면 sscanf의 속도가 느리다고 하는데.. 맞는가봄..
일단 boost의 경우 자리수를 지정해서 그 만큼 짤라내는게 아주 잘 되고..
sscanf보다 빠르니.. 요걸 쓰기로 결정..

CGAL Build on MinGW

MinGW상에서 CGAL 빌드 방법.

1) download boost sources and compile it (I use boost 1.47.0):

a) generate b2.exe (jam) by typing in a console "bootstrap.bat mingw" 
  b) type in a console: b2.exe --prefix=<absolute_path_to_boost64> 
toolset=gcc address-model=64 variant=debug,release link=static,shared 
threading=multi install 
Before, I tried an external version of boost-jam like described here: 
http://sourceforge.net/apps/trac/mingw-w64/wiki/Building%20Boost
but bjam.exe failed to build boost.

2) build CGAL libraries (I use cgal 3.9):

  a) Use cmake-gui 
  b) before configuring, setup the BOOST_ROOT path variable to you BOOST 
directory. 
  c) optional (this doesn't work for me): setup the Boost_LIBRARYDIR to 
your boost\lib dir 
  d) configure 
  e) optional: check demos and examples and configure again 
  f) generate 
  g) type in a console mingw32-make 
  h) if you have troubles with emmintrin.h and intrin.h, you must add a 
"#include <windows.h>" at the top of the file "all_files.cpp" in the 
src/ImageIO directory generated by cmake 

혹시.. double.h 파일에서 에러가 나면 다음을 추가.

#if defined ( _MSC_VER )
#define CGAL_ALIGN_16  __declspec(align(16))
#elif defined( __GNU__ ) || defined( __MINGW32__ )
#define  CGAL_ALIGN_16 __attribute__((aligned(16))) 
#endif


#ifdef CGAL_USE_SSE2_FABS   
inline double sse2fabs(double a)
{
  static CGAL_ALIGN_16 const union{

3) build demos and examples (if checked in cmake):

 - type mingw32-make demos 
for me, it doesn't link with boost (even with the 2)c) option), so demos 
generation failed. I didn't try examples, but I manualy compile an 
example: circulator 
I used those commands: 
g++ -c circulator_prog1.cpp -frounding-math -I../../include 
-I../../build/include 
-I../../../../boost_1_47_0/mingw64/include/boost-1_47 -o circulator_prog1.o 
g++ circulator_prog1.o -L../../build/lib -lCGAL 
-L../../../../boost_1_47_0/mingw64/lib -lboost_thread-mgw44-mt-1_47 -o 
circulator_prog1.exe 
where /build is the build folder "where to build binaries" for cmake. 

Boost 빌드 for MinGW

몇번의 시도끝에 얻은 MinGW 용 Boot 빌드 방법.

cmd 창에서 아래를 입력

set path=%path%;C:\MinGW-4.6.1\mingw\bin
bootstrap.bat mingw

다음 32비트의 경우..

b2.exe --prefix=C:\boost_1_55_0\release\win32 toolset=gcc variant=debug,release threading=multi install 

64비트의 경우는..

b2.exe --prefix=C:\boost_1_55_0\release\win64 toolset=gcc address-model=64 variant=debug,release threading=multi install

boost

홈페이지: http://www.boost.org/

범용으로 빈번하게 사용되는 작은 유틸리티들을 제공하려는 프로젝트.
그래프, 쓰레기 수집 기능을 가진 포인터, 파일시스템, 수학 연산들, 쓰레드, 스캐너와 LL파서 등 유용한 기능을 가진 라이브러리들을 많이 확보하고 있음.

Boost provides free peer-reviewed portable C++ source libraries.

We emphasize libraries that work well with the C++ Standard Library. Boost libraries are intended to be widely useful, and usable across a broad spectrum of applications. The Boost license encourages both commercial and non-commercial use.

다운로드: 1.34.1