1// Copyright (C) 2004, 2009 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 29using namespace std; 30using namespace __gnu_test; 31 32const int length = 10000000; 33const int match_length = 3; 34int array[length]; 35 36int 37main(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 array[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(array, array + length); 48 start_counters(time, resource); 49 for(int i = 0; i < 100; i++) 50 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(array, array + length); 56 start_counters(time, resource); 57 for(int i = 0; i < 100; i++) 58 search_n(rcon.begin(), rcon.end(), 10, 1); 59 stop_counters(time, resource); 60 report_performance(__FILE__, "random acess iterator", time, resource); 61 clear_counters(time, resource); 62} 63 64