| 1 | // Copyright (C) 2004-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 | |
| 19 | #define DISABLE_ITERATOR_DEBUG 1 |
| 20 | |
| 21 | #include<cstdlib> |
| 22 | #include<vector> |
| 23 | #include<algorithm> |
| 24 | |
| 25 | #include<sstream> |
| 26 | #include<testsuite_performance.h> |
| 27 | #include<testsuite_iterators.h> |
| 28 | |
| 29 | using namespace std; |
| 30 | using namespace __gnu_test; |
| 31 | |
| 32 | const int length = 10000000; |
| 33 | const int match_length = 3; |
| 34 | int ary[length]; |
| 35 | |
| 36 | int |
| 37 | main(void) |
| 38 | { |
| 39 | time_counter time; |
| 40 | resource_counter resource; |
| 41 | int match = rand() % (match_length - 1); |
| 42 | for(int i = 0; i < length; i++) |
| 43 | { |
| 44 | ary[i] = (match != 0) ? 1 : 0; |
| 45 | if(--match < 0) match = rand() % (match_length - 1); |
| 46 | } |
| 47 | __gnu_test::test_container<int, forward_iterator_wrapper> fcon(ary, ary + length); |
| 48 | start_counters(time, resource); |
| 49 | for(int i = 0; i < 100; i++) |
| 50 | (void) search_n(fcon.begin(), fcon.end(), 10, 1); |
| 51 | stop_counters(time, resource); |
| 52 | report_performance(__FILE__, "forward iterator", time, resource); |
| 53 | clear_counters(time, resource); |
| 54 | |
| 55 | __gnu_test::test_container<int, random_access_iterator_wrapper> rcon(ary, ary + length); |
| 56 | start_counters(time, resource); |
| 57 | for(int i = 0; i < 100; i++) |
| 58 | (void) search_n(rcon.begin(), rcon.end(), 10, 1); |
| 59 | stop_counters(time, resource); |
| 60 | report_performance(__FILE__, "random access iterator", time, resource); |
| 61 | clear_counters(time, resource); |
| 62 | } |
| 63 |