| 1 |
// Copyright (C) 2005-2025 Free Software Foundation, Inc. |
| 2 |
// |
| 3 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 4 |
// software; you can redistribute it and/or modify it under the |
| 5 |
// terms of the GNU General Public License as published by the |
| 6 |
// Free Software Foundation; either version 3, or (at your option) |
| 7 |
// any later version. |
| 8 |
|
| 9 |
// This library is distributed in the hope that it will be useful, |
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
// GNU General Public License for more details. |
| 13 |
|
| 14 |
// You should have received a copy of the GNU General Public License along |
| 15 |
// with this library; see the file COPYING3. If not see |
| 16 |
// <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
#include <unistd.h> |
| 19 |
#include <cstdio> |
| 20 |
#include <fstream> |
| 21 |
#include <string> |
| 22 |
#include <testsuite_performance.h> |
| 23 |
|
| 24 |
// libstdc++/22515 |
| 25 |
int main() |
| 26 |
{ |
| 27 |
using namespace std; |
| 28 |
using namespace __gnu_test; |
| 29 |
|
| 30 |
time_counter time; |
| 31 |
resource_counter resource; |
| 32 |
|
| 33 |
const char filename[] = "tmp_perf_chars.txt"; |
| 34 |
const unsigned lines = 200000; |
| 35 |
const unsigned line_length = 200; |
| 36 |
|
| 37 |
char* line = new char[line_length + 2]; |
| 38 |
|
| 39 |
// Construct data. |
| 40 |
{ |
| 41 |
memset(line, 'x', line_length); |
| 42 |
line[line_length] = '\n'; |
| 43 |
line[line_length + 1] = '\0'; |
| 44 |
|
| 45 |
ofstream out(filename); |
| 46 |
for (unsigned i = 0; i < lines; ++i) |
| 47 |
out << line; |
| 48 |
} |
| 49 |
|
| 50 |
// operator>>(basic_istream<char>& __in, basic_string<char>& __str) |
| 51 |
{ |
| 52 |
start_counters(time, resource); |
| 53 |
for (int iter = 0; iter < 25; ++iter) |
| 54 |
{ |
| 55 |
ifstream file(filename); |
| 56 |
string string_line; |
| 57 |
|
| 58 |
while (file >> string_line); |
| 59 |
} |
| 60 |
stop_counters(time, resource); |
| 61 |
report_performance(__FILE__, "string&", time, resource); |
| 62 |
clear_counters(time, resource); |
| 63 |
} |
| 64 |
|
| 65 |
// operator>>(basic_istream<char>& __in, char* __s) |
| 66 |
{ |
| 67 |
start_counters(time, resource); |
| 68 |
for (int iter = 0; iter < 25; ++iter) |
| 69 |
{ |
| 70 |
ifstream file(filename); |
| 71 |
|
| 72 |
while (file >> line); |
| 73 |
} |
| 74 |
stop_counters(time, resource); |
| 75 |
report_performance(__FILE__, "char*", time, resource); |
| 76 |
clear_counters(time, resource); |
| 77 |
} |
| 78 |
|
| 79 |
delete[] line; |
| 80 |
unlink(filename); |
| 81 |
return 0; |
| 82 |
} |