predefine all buffers
....
profit
Oh and no spam. Sample code in 5 to 10 minutes.
Good here: also Live On Coliru
#include <string>
#include <sstream>
#include <boost/utility/string_ref.hpp>
template <typename Range>
int expand(Range const& )
{
return rand()%42;
}
#include <iostream>
int main()
{
static const std::string msg_template = "{A}jahshs{b}jwuw{c}wuqjwhaha{d}{e}{f}jsj{g}\n";
std::ostringstream builder;
builder.str().reserve(1024);
for (size_t iterations = 1ul << 14; iterations; --iterations)
{
builder.str("");
std::ostreambuf_iterator<char> out(builder);
for(auto f(msg_template.begin()), l(msg_template.end()); f != l;)
{
switch(*f)
{
case '{' :
{
auto s = ++f;
size_t n = 0;
while (f!=l && *f != '}')
++f, ++n;
builder << expand(boost::string_ref(&*s, n));
if (f!=l)
++f;
}
break;
default:
*out++ = *f++;
}
}
}
}
~ 0.239s . Thats about 68k expansions/second.
. 4 /. Coliru 1 /.
:
- , 1 , string_ref char,
'}'. - . ( , ).