1// Copyright (C) 2003-2015 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#include <testsuite_performance.h> 20 21template<typename Container, int Iter> 22 void 23 do_loop() 24 { 25 // XXX 26 const int iter = 150000; 27 typedef Container container_type; 28 container_type obj; 29 int ctr = 3; 30 while (ctr--) 31 { 32 for (int i = 0; i < iter; ++i) 33 obj.push_back(rand()%500001); 34 35 //Search for random values that may or may not belong to the list. 36 for (int i = 0; i < 50; ++i) 37 std::find(obj.begin(), obj.end(), rand() % 100001); 38 39 obj.sort(); 40 41 //Search for random values that may or may not belong to the list. 42 for (int i = 0; i < 50; ++i) 43 { 44 typedef typename container_type::iterator iterator_type; 45 iterator_type _liter = std::find(obj.begin(), obj.end(), 46 rand() % 100001); 47 if (_liter != obj.end()) 48 obj.erase(_liter); 49 } 50 obj.clear(); 51 } 52 } 53 54int 55main() 56{ 57#ifdef TEST_S1 58#define thread_type false 59#endif 60 61#ifdef TEST_T1 62#define thread_type true 63#endif 64 65 typedef __gnu_test::lists<int, thread_type>::type container_types; 66 typedef test_sequence<thread_type> test_type; 67 test_type test("sort_search"); 68 __gnu_cxx::typelist::apply(test, container_types()); 69 70 return 0; 71} 72 73