This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Another test case for bitmapped allocator.
- From: Dhruv Matani <dhruvbird at gmx dot net>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>, Loren James Rittle <rittle at latour dot rsch dot comm dot mot dot com>
- Date: 14 Jan 2004 19:25:24 +0530
- Subject: Another test case for bitmapped allocator.
- Organization:
I'm attaching another test case. You can see that the botmapped
allocator is almost always better than the default node allocator in
terms of speed.
//Bitmapped allocator.
[dhruv@home test]$ compile balloc_test.cpp -O3
[dhruv@home test]$ ./balloc_test
Time Taken to Insert: 0.12 Seconds.
Time Taken to Search: 0.44 Seconds.
Size is: 550000
Time Taken to Sort: 1.2 Seconds.
Time Taken to Search: 5 Seconds.
Size is: 493251
Time Taken to Insert: 0.11 Seconds.
Time Taken to Search: 4.75 Seconds.
Size is: 1043251
Time Taken to Sort: 2.21 Seconds.
Time Taken to Search: 10.65 Seconds.
Size is: 0
Time Taken to Insert: 0.12 Seconds.
Time Taken to Search: 0.44 Seconds.
Size is: 550000
Time Taken to Sort: 1.2 Seconds.
Time Taken to Search: 5.29 Seconds.
Size is: 94199
3
[dhruv@home test]$
[dhruv@home test]$
//Default Node allocator.
[dhruv@home test]$ compile balloc_test.cpp -O3
[dhruv@home test]$ ./balloc_test
Time Taken to Insert: 0.12 Seconds.
Time Taken to Search: 0.55 Seconds.
Size is: 550000
Time Taken to Sort: 1.27 Seconds.
Time Taken to Search: 5.19 Seconds.
Size is: 493251
Time Taken to Insert: 0.14 Seconds.
Time Taken to Search: 5.29 Seconds.
Size is: 1043251
Time Taken to Sort: 2.46 Seconds.
Time Taken to Search: 11.33 Seconds.
Size is: 0
Time Taken to Insert: 0.28 Seconds.
Time Taken to Search: 4.44 Seconds.
Size is: 550000
Time Taken to Sort: 2.28 Seconds.
Time Taken to Search: 6.09 Seconds.
Size is: 94199
3
[dhruv@home test]$
--
-Dhruv Matani.
http://www.geocities.com/dhruvbird/
#include <nstl/balloc.hpp>
#include <nstl/node_alloc.hpp>
#include <list>
#include <algorithm>
#include <nstl/timer.hpp>
#include <cstdlib>
#include <iostream>
using namespace std;
using nstd::bitmap_allocator;
int main ()
{
nstd::timer t;
// typedef std::list<int, bitmap_allocator<int> > My_List;
typedef std::list<int> My_List;
//std::list<int, nstd::node_allocator<int> > il1;
// nstd::node_allocator<int> ba;
My_List il1;
int ctr = 3;
while (ctr--)
{
t.start ();
for (int i = 0; i < 550000; ++i)
il1.push_back (rand()%10001);
t.stop ();
cout<<"Time Taken to Insert: "<<t.difference()<<" Seconds."<<endl;
//Search for random values that may or may not belong to the list.
t.start ();
for (int i = 0; i < 50; ++i)
std::find (il1.begin(), il1.end(), rand()%20001);
t.stop ();
cout<<"Time Taken to Search: "<<t.difference()<<" Seconds."<<endl;
My_List::iterator i = il1.begin();
cout<<"Size is: "<<il1.size ()<<endl;
t.start ();
il1.sort ();
t.stop ();
cout<<"Time Taken to Sort: "<<t.difference()<<" Seconds."<<endl;
//Search for random values that may or may not belong to the list.
t.start ();
for (int i = 0; i < 50; ++i)
std::find (il1.begin(), il1.end(), rand()%20001);
t.stop ();
cout<<"Time Taken to Search: "<<t.difference()<<" Seconds."<<endl;
// il1.clear ();
il1.erase (i, il1.end());
cout<<"Size is: "<<il1.size ()<<endl<<endl;
}
il1.clear ();
int x;
cin>>x;
}