http://www.partow.net/programming/strtk/index.html

 

Tokenizer Test
[boost]   Tokens:  24000000    Time:  3.1728sec    Rate:  7564286.9840tks/sec 57.11MB/s
[strtk]   Tokens:  24000000    Time:  1.5632sec    Rate: 15352836.9804tks/sec 115.91MB/s
Split Test
[boost]   Tokens:   9600000    Time:  2.5366sec    Rate:  3784608.4704tks/sec 28.57MB/s
[strtk]   Tokens:   9600000    Time:  0.7261sec    Rate: 13221337.5862tks/sec 99.82MB/s
Integer To String Test
[sprintf] Numbers:  80000000    Total:   657777787    Time:  7.6938sec    Rate: 10397921.9753nums/sec
[boost]   Numbers:  80000000    Total:   657777787    Time:  9.4267sec    Rate:  8486518.5288nums/sec
[strtk]   Numbers:  80000000    Total:   657777787    Time:  1.7255sec    Rate: 46362513.1264nums/sec
String To Integer Test
[atoi]    Numbers: 184000000    Total:  -188243392    Time:  4.8301sec    Rate: 38094197.0116nums/sec
[boost]   Numbers: 184000000    Total:  -188243392    Time: 54.8367sec    Rate:  3355418.9807nums/sec
[strtk]   Numbers: 184000000    Total:  -188243392    Time:  2.0919sec    Rate: 87956675.6010nums/sec
[fast]    Numbers: 184000000    Total:  -188243392    Time:  2.3611sec    Rate: 77930504.6254nums/sec
String To Double Test
[atof]    Numbers:  75040000    Error:0.133514970373    Time:  9.4313sec    Rate:  7956503.0363nums/sec
[boost]   Numbers:  75040000    Error:0.133514970373    Time: 37.9114sec    Rate:  1979351.9094nums/sec
[strtk]   Numbers:  75040000    Error:0.133514970373    Time:  2.3694sec    Rate: 31670438.3638nums/sec

 

   std::string s ;
   int i = -1000 ;
   strtk::type_to_string(i,s);
   std::cout << "(" << s << ")" << std::endl;
   i = 10002000 ;
   strtk::type_to_string(i,s);
   std::cout << "(" << s << ")" << std::endl;
   double d1 = -1.3456 , d2 = 345.67891 ;
   std::string s1,s2 ;
   strtk::type_to_string(d1,s1);
   strtk::type_to_string(d2,s2);
   std::cout << "(" << s1 << ")(" << s2 << ")" << std::endl;

 

void tokenizer_example01()
{
   std::cout << "tokenizer_example01" << std::endl;
   std::string s = "abc|123|xyz|789";
   strtk::single_delimiter_predicate<std::string::value_type> predicate('|');
   typedef strtk::std_string::tokenizer<>::type tokenizer_type;

   tokenizer_type tokenizer(s,predicate);
   tokenizer_type::iterator itr = tokenizer.begin();

   while (tokenizer.end() != itr)
   {
      std::cout << "[" << itr << "]\t";
      ++itr;
   }

   std::cout << std::endl;
}

void tokenizer_example02()
{
   std::cout << "tokenizer_example02" << std::endl;
   std::string s = "abc.123 xyz?789";
   strtk::multiple_char_delimiter_predicate predicate(" .;?");

   typedef strtk::std_string::tokenizer<strtk::multiple_char_delimiter_predicate>::type tokenizer_type;

   tokenizer_type tokenizer(s,predicate,strtk::tokenize_options::compress_delimiters);
   tokenizer_type::iterator itr = tokenizer.begin();

   while (tokenizer.end() != itr)
   {
      std::cout << "[" << itr << "]\t";
      ++itr;
   }

   std::cout << std::endl;
}

void tokenizer_example03()
{
   std::cout << "tokenizer_example03" << std::endl;
   std::string s = "abc||123|||||xyz|789";
   strtk::single_delimiter_predicate<std::string::value_type> predicate('|');

   typedef strtk::std_string::tokenizer<>::type tokenizer_type;

   tokenizer_type tokenizer(s,predicate,strtk::tokenize_options::compress_delimiters);
   tokenizer_type::iterator itr = tokenizer.begin();

   while (tokenizer.end() != itr)
   {
      std::cout << "[" << itr << "]\t";
      ++itr;
   }

   std::cout << std::endl;
}

void tokenizer_example04()
{
   std::cout << "tokenizer_example04" << std::endl;
   std::string s = "abc.;123? xyz;?789";
   strtk::multiple_char_delimiter_predicate predicate(" .;?");

   typedef strtk::std_string::tokenizer<strtk::multiple_char_delimiter_predicate>::type tokenizer_type;

   tokenizer_type tokenizer(s,predicate,strtk::tokenize_options::compress_delimiters);
   tokenizer_type::iterator itr = tokenizer.begin();

   while (tokenizer.end() != itr)
   {
      std::cout << "[" << itr << "]\t";
      ++itr;
   }

   std::cout << std::endl;
}

void tokenizer_example05()
{
   std::cout << "tokenizer_example05" << std::endl;
   unsigned int data[] = {1,2,3,0,4,5,6,0,7,8,0,9};
   const std::size_t data_size = sizeof(data) / sizeof(unsigned int);
   strtk::single_delimiter_predicate<unsigned int> predicate(0);

   typedef strtk::tokenizer< unsigned int*,strtk::single_delimiter_predicate<unsigned int> > tokenizer_type;
   tokenizer_type tokenizer(data,data + data_size,predicate);
   tokenizer_type::iterator itr = tokenizer.begin();

   while (tokenizer.end() != itr)
   {
      std::cout << "[" << strtk::join(" ",(*itr).first,(*itr).second) << "]";
      ++itr;
   }

   std::cout << std::endl;
}

void tokenizer_example06()
{
   std::cout << "tokenizer_example06" << std::endl;
   unsigned int data[] = {1,2,3,0,4,5,6,10,7,8,0,9};
   const std::size_t data_size = sizeof(data) / sizeof(unsigned int);
   unsigned int delimiters[2] = {0,10};
   strtk::multiple_delimiter_predicate<unsigned int> predicate(delimiters,delimiters + 2);

   typedef strtk::tokenizer< unsigned int*,strtk::multiple_delimiter_predicate<unsigned int> > tokenizer_type;
   tokenizer_type tokenizer(data,data + data_size,predicate);
   tokenizer_type::iterator itr = tokenizer.begin();

   while (tokenizer.end() != itr)
   {
      std::cout << "[" << strtk::join(" ",(*itr).first,(*itr).second) << "]";
      ++itr;
   }

   std::cout << std::endl;
}

創作者介紹
創作者 hedgezzz 的頭像
hedgezzz

hedgezzz的部落格

hedgezzz 發表在 痞客邦 留言(0) 人氣()