ifstream_extract_float.cc: Add higher precision tests.

2
2004-01-13  Benjamin Kosnik  <bkoz@redhat.com>

	* testsuite/performance/ifstream_extract_float.cc: Add higher
	precision tests.
	* testsuite/performance/ofstream_insert_float.cc: Same.

From-SVN: r75841
This commit is contained in:
Benjamin Kosnik 2004-01-14 04:11:57 +00:00 committed by Benjamin Kosnik
parent 5b8d96f109
commit 070ce57b95
3 changed files with 60 additions and 24 deletions

View File

@ -1,3 +1,9 @@
2004-01-13 Benjamin Kosnik <bkoz@redhat.com>
* testsuite/performance/ifstream_extract_float.cc: Add higher
precision tests.
* testsuite/performance/ofstream_insert_float.cc: Same.
2004-01-13 Paolo Carlini <pcarlini@suse.de>
* src/locale-misc-inst.cc (__convert_from_v(long),

View File

@ -26,36 +26,51 @@
// the GNU General Public License.
#include <fstream>
#include <sstream>
#include <testsuite_performance.h>
int main()
void test_extraction(int p = 6)
{
using namespace std;
using namespace __gnu_test;
time_counter time;
resource_counter resource;
const char* filename = "tmp_perf_float.txt";
const int iterations = 10000000;
ostringstream oss;
oss << "precision " << p;
// Construct data.
{
ofstream out("tmp_perf_float.txt");
ofstream out(filename);
out.precision(p);
for (int i = 0; i < iterations; ++i)
{
float f = i * 3.14159265358979323846;
out << f << "\n";
out << f << '\n';
}
}
{
ifstream in("tmp_perf_float.txt");
time_counter time;
resource_counter resource;
ifstream in(filename);
in.precision(p);
float f;
start_counters(time, resource);
for (int j, i = 0; i < iterations; ++i)
in >> f;
stop_counters(time, resource);
report_performance(__FILE__, "", time, resource);
report_performance(__FILE__, oss.str(), time, resource);
}
unlink("tmp_perf_int.txt");
return 0;
unlink(filename);
};
int main()
{
test_extraction(6);
test_extraction(12);
return 0;
}

View File

@ -26,28 +26,43 @@
// the GNU General Public License.
#include <fstream>
#include <sstream>
#include <testsuite_performance.h>
// based on libstdc++/8761 poor fstream performance (converted to float)
int main()
// Based on libstdc++/8761 poor fstream performance (converted to float)
void test_insertion(int p = 6)
{
using namespace std;
using namespace __gnu_test;
time_counter time;
resource_counter resource;
const char* filename = "tmp_perf_float.txt";
const int iterations = 10000000;
ofstream out("tmp_perf_float.txt");
start_counters(time, resource);
for (int i = 0; i < iterations; ++i)
{
float f = i * 3.14159265358979323846;
out << f << "\n";
}
stop_counters(time, resource);
report_performance(__FILE__, "", time, resource);
ostringstream oss;
oss << "precision " << p;
unlink("tmp_perf_float.txt");
return 0;
{
time_counter time;
resource_counter resource;
ofstream out(filename);
out.precision(p);
start_counters(time, resource);
for (int i = 0; i < iterations; ++i)
{
float f = i * 3.14159265358979323846;
out << f << '\n';
}
stop_counters(time, resource);
report_performance(__FILE__, oss.str(), time, resource);
}
unlink(filename);
};
int main()
{
test_insertion(6);
test_insertion(12);
return 0;
}