copy_streambuf_iterators.cc [plain text]
#include <iterator>
#include <sstream>
#include <algorithm>
#include <testsuite_performance.h>
int main()
{
using namespace std;
using namespace __gnu_test;
typedef istreambuf_iterator<char> in_iterator_type;
typedef ostreambuf_iterator<char> out_iterator_type;
time_counter time;
resource_counter resource;
const char data[] = "Contrappunto dialettico alla mente";
{
istringstream iss(data);
in_iterator_type beg(iss);
in_iterator_type end;
ostringstream oss;
out_iterator_type out(oss);
start_counters(time, resource);
for (unsigned i = 0; i < 10000000; ++i)
{
copy(beg, end, out);
iss.seekg(0);
oss.seekp(0);
}
stop_counters(time, resource);
report_performance(__FILE__, "isb iters -> osb iter", time, resource);
clear_counters(time, resource);
}
{
const char* beg = data;
const char* end = data + sizeof(data) - 1;
ostringstream oss;
out_iterator_type out(oss);
start_counters(time, resource);
for (unsigned i = 0; i < 10000000; ++i)
{
copy(beg, end, out);
oss.seekp(0);
}
stop_counters(time, resource);
report_performance(__FILE__, "pointers -> osb iter", time, resource);
clear_counters(time, resource);
}
{
istringstream iss(data);
in_iterator_type beg(iss);
in_iterator_type end;
char out[sizeof(data)];
start_counters(time, resource);
for (unsigned i = 0; i < 10000000; ++i)
{
copy(beg, end, out);
iss.seekg(0);
}
stop_counters(time, resource);
report_performance(__FILE__, "isb iters -> pointer", time, resource);
clear_counters(time, resource);
}
return 0;
}