1 // Copyright (C) 2004-2019 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 int iterations
= 500000;
34 const int chunksize
= 100;
36 char* chunk
= new char[chunksize
];
37 const char* name1
= "/usr/share/dict/words";
38 const char* name2
= "/usr/share/dict/linux.words";
39 const char* name
= name1
;
43 if (!(file
= fopen(name
, "r")))
46 if (!(file
= fopen(name
, "r")))
49 setvbuf(file
, 0, _IONBF
, 0);
50 start_counters(time
, resource
);
51 for (int i
= 0; i
< iterations
; ++i
)
52 if (fread(chunk
, 1, chunksize
, file
) < chunksize
)
53 fseek(file
, 0, SEEK_SET
);
54 stop_counters(time
, resource
);
56 report_performance(__FILE__
, "C", time
, resource
);
57 clear_counters(time
, resource
);
60 file
= fopen(name
, "r");
61 setvbuf(file
, 0, _IONBF
, 0);
62 start_counters(time
, resource
);
63 for (int i
= 0; i
< iterations
; ++i
)
64 if (fread_unlocked(chunk
, 1, chunksize
, file
) < chunksize
)
65 fseek(file
, 0, SEEK_SET
);
66 stop_counters(time
, resource
);
68 report_performance(__FILE__
, "C unlocked", time
, resource
);
69 clear_counters(time
, resource
);
74 buf
.open(name
, ios_base::in
);
75 start_counters(time
, resource
);
76 for (int i
= 0; i
< iterations
; ++i
)
77 if (buf
.sgetn(chunk
, chunksize
) < chunksize
)
78 buf
.pubseekoff(0, ios::beg
);
79 stop_counters(time
, resource
);
80 report_performance(__FILE__
, "C++", time
, resource
);