From 070ce57b9526cf19d545ed56a9f4a2475a2c9261 Mon Sep 17 00:00:00 2001 From: Benjamin Kosnik Date: Wed, 14 Jan 2004 04:11:57 +0000 Subject: [PATCH] ifstream_extract_float.cc: Add higher precision tests. 2 2004-01-13 Benjamin Kosnik * testsuite/performance/ifstream_extract_float.cc: Add higher precision tests. * testsuite/performance/ofstream_insert_float.cc: Same. From-SVN: r75841 --- libstdc++-v3/ChangeLog | 6 +++ .../performance/ifstream_extract_float.cc | 33 ++++++++++---- .../performance/ofstream_insert_float.cc | 45 ++++++++++++------- 3 files changed, 60 insertions(+), 24 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 0c0720e60af5..fab586eb6bda 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2004-01-13 Benjamin Kosnik + + * testsuite/performance/ifstream_extract_float.cc: Add higher + precision tests. + * testsuite/performance/ofstream_insert_float.cc: Same. + 2004-01-13 Paolo Carlini * src/locale-misc-inst.cc (__convert_from_v(long), diff --git a/libstdc++-v3/testsuite/performance/ifstream_extract_float.cc b/libstdc++-v3/testsuite/performance/ifstream_extract_float.cc index 5c6b42195412..55710c2afce9 100644 --- a/libstdc++-v3/testsuite/performance/ifstream_extract_float.cc +++ b/libstdc++-v3/testsuite/performance/ifstream_extract_float.cc @@ -26,36 +26,51 @@ // the GNU General Public License. #include +#include #include -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; +} diff --git a/libstdc++-v3/testsuite/performance/ofstream_insert_float.cc b/libstdc++-v3/testsuite/performance/ofstream_insert_float.cc index 57e8c0e70779..45d55af01bfa 100644 --- a/libstdc++-v3/testsuite/performance/ofstream_insert_float.cc +++ b/libstdc++-v3/testsuite/performance/ofstream_insert_float.cc @@ -26,28 +26,43 @@ // the GNU General Public License. #include +#include #include -// 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; +}