@@ -54,15 +54,15 @@ static void BenchStringSplit(benchmark::State &state)
5454{
5555 std::string tag = " 1,2,3,4,5,6,7,8,9,0,1,2,3,4,6,1,2,3,4,56,7,8,9,09,12" ;
5656 int r = 0 ;
57- std::vector<std::string> vec;
57+
5858 for (auto _ : state)
5959 {
60+ std::vector<std::string> vec;
6061 StringSplit (tag, " ," , vec);
6162 for (auto &i : vec)
6263 {
6364 r += i.size ();
6465 }
65- vec.clear ();
6666 }
6767 benchmark::DoNotOptimize (r);
6868}
@@ -73,15 +73,15 @@ static void BenchStringSplitStream(benchmark::State &state)
7373{
7474 std::string tag = " 1,2,3,4,5,6,7,8,9,0,1,2,3,4,6,1,2,3,4,56,7,8,9,09,12" ;
7575 int r = 0 ;
76- std::vector<std::string> vec;
76+
7777 for (auto _ : state)
7878 {
79+ std::vector<std::string> vec;
7980 StringSplitStream (tag, ' ,' , vec);
8081 for (auto &i : vec)
8182 {
8283 r += i.size ();
8384 }
84- vec.clear ();
8585 }
8686 benchmark::DoNotOptimize (r);
8787}
@@ -92,15 +92,14 @@ static void BenchBoostSplit(benchmark::State &state)
9292{
9393 std::string tag = " 1,2,3,4,5,6,7,8,9,0,1,2,3,4,6,1,2,3,4,56,7,8,9,09,12" ;
9494 int r = 0 ;
95- std::vector<std::string> vec;
9695 for (auto _ : state)
9796 {
97+ std::vector<std::string> vec;
9898 boost::split (vec, tag, [](char c) { return c = ' ,' ; });
9999 for (auto &i : vec)
100100 {
101101 r += i.size ();
102102 }
103- vec.clear ();
104103 }
105104 benchmark::DoNotOptimize (r);
106105}
@@ -128,15 +127,14 @@ static void BenchPBSplit(benchmark::State &state)
128127{
129128 std::string tag = " 1,2,3,4,5,6,7,8,9,0,1,2,3,4,6,1,2,3,4,56,7,8,9,09,12" ;
130129 int r = 0 ;
131- std::vector<std::string> vec;
132130 for (auto _ : state)
133131 {
132+ std::vector<std::string> vec;
134133 google::protobuf::SplitStringAllowEmpty (tag, " ," , &vec);
135134 for (auto &i : vec)
136135 {
137136 r += i.size ();
138137 }
139- vec.clear ();
140138 }
141139 benchmark::DoNotOptimize (r);
142140}
0 commit comments