OSDN Git Service

2004-03-22 Paolo Carlini <pcarlini@suse.de>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / performance / 20_util / allocator / list_sort_search.cc
1 // Copyright (C) 2004 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 2, 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 COPYING.  If not, write to the Free
16 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 // USA.
18
19 // As a special exception, you may use this file as part of a free software
20 // library without restriction.  Specifically, if other files instantiate
21 // templates or use macros or inline functions from this file, or you compile
22 // this file and link it with other files to produce an executable, this
23 // file does not by itself cause the resulting executable to be covered by
24 // the GNU General Public License.  This exception does not however
25 // invalidate any other reasons why the executable file might be covered by
26 // the GNU General Public License.
27
28 // 2004-03-11  Dhruv Matani  <dhruvbird@HotPOP.com>
29
30 #include <typeinfo>
31 #include <sstream>
32 #include <ext/mt_allocator.h>
33 #include <ext/malloc_allocator.h>
34 #include <cxxabi.h>
35 #include <testsuite_performance.h>
36 #include <ext/bitmap_allocator.h>
37 #include <ext/pool_allocator.h>
38
39 using namespace std;
40 using __gnu_cxx::malloc_allocator;
41 using __gnu_cxx::__mt_alloc;
42 using __gnu_cxx::bitmap_allocator;
43 using __gnu_cxx::__pool_alloc;
44
45 typedef int test_type;
46
47 using namespace __gnu_cxx;
48
49 #include <list>
50 #include <map>
51 #include <algorithm>
52 #include <cstdlib>
53 using namespace std;
54
55 template <typename Alloc>
56 int Test_Allocator ()
57 {
58   typedef list<int, Alloc> My_List;
59   My_List il1;
60
61   int const Iter = 150000;
62
63   int ctr = 3;
64   while (ctr--)
65     {
66       for (int i = 0; i < Iter; ++i)
67         il1.push_back (rand()%500001);
68
69       //Search for random values that may or may not belong to the list.
70       for (int i = 0; i < 50; ++i)
71         std::find (il1.begin(), il1.end(), rand()%100001);
72       
73       il1.sort ();
74       
75       //Search for random values that may or may not belong to the list.
76       for (int i = 0; i < 50; ++i)
77         {
78           typename My_List::iterator _liter = std::find (il1.begin(), il1.end(), rand()%100001);
79           if (_liter != il1.end())
80             il1.erase (_liter);
81         }
82       
83       il1.clear ();
84     }
85   return Iter;
86 }
87
88 template <typename Alloc>
89 void do_test ()
90 {
91   using namespace __gnu_test;
92   int status;
93   Alloc obj;
94
95   time_counter time;
96   resource_counter resource;
97   clear_counters(time, resource);
98   start_counters(time, resource);
99   int test_iterations = Test_Allocator<Alloc>();
100   stop_counters(time, resource);
101  
102   std::ostringstream comment;
103   comment << "iterations: " << test_iterations <<endl;
104   comment << "type: " << abi::__cxa_demangle(typeid(obj).name(),
105                                              0, 0, &status);
106   report_header(__FILE__, comment.str());
107   report_performance(__FILE__, string(), time, resource);
108 }
109
110 int main ()
111 {
112 #ifdef TEST_S0
113   do_test<new_allocator<int> >();
114 #endif
115 #ifdef TEST_S1
116   do_test<malloc_allocator<int> >();
117 #endif
118 #ifdef TEST_S2
119   do_test<bitmap_allocator<int> >();
120 #endif
121 #ifdef TEST_S3
122   do_test<__mt_alloc<int> >();
123 #endif
124 #ifdef TEST_S4
125   do_test<__pool_alloc<int> >();
126 #endif
127 }
128
129