1 // Copyright (C) 2004-2021 Free Software Foundation, Inc.
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)
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.
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/>.
22 #include <testsuite_performance.h>
28 using namespace __gnu_test
;
31 resource_counter resource
;
33 const char filename
[] = "tmp_getline.txt";
34 const unsigned lines
= 1000000;
35 const unsigned line_length
= 200;
37 char* line
= new char[line_length
+ 2];
41 memset(line
, 'x', line_length
);
42 line
[line_length
] = '\n';
43 line
[line_length
+ 1] = '\0';
45 ofstream
out(filename
);
46 for (unsigned i
= 0; i
< lines
; ++i
)
53 FILE *file
= fopen(filename
, "r");
54 while (fgets(line
, line_length
+ 2, file
));
57 file
= fopen(filename
, "r");
58 start_counters(time
, resource
);
59 while (fgets(line
, line_length
+ 2, file
));
60 stop_counters(time
, resource
);
62 report_performance(__FILE__
, "C (fgets)", time
, resource
);
63 clear_counters(time
, resource
);
66 // getline(basic_istream<_CharT, _Traits>& __in,
67 // basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim)
69 ifstream
file(filename
);
72 start_counters(time
, resource
);
73 while (getline(file
, string_line
));
74 stop_counters(time
, resource
);
75 report_performance(__FILE__
, "C++ (string)", time
, resource
);
76 clear_counters(time
, resource
);
79 // getline(char_type* __s, streamsize __n, char_type __delim)
81 ifstream
file(filename
);
83 start_counters(time
, resource
);
84 while (file
.getline(line
, line_length
+ 2));
85 stop_counters(time
, resource
);
86 report_performance(__FILE__
, "C++ (char array)", time
, resource
);
87 clear_counters(time
, resource
);