vector<> can probably never grow to it's maximum size!
Dhruv Matani
dhruvbird@gmx.net
Wed Oct 20 15:07:00 GMT 2004
On Wed, 2004-10-20 at 19:58, Paolo Carlini wrote:
> Dhruv Matani wrote:
>
> >What I am trying to do for the __mt_alloc is NOT reallocate memory, but
> >reuse a memory region if it is already over-allocated(as in the case of
> >__mt_alloc because it uses bins of 2^N size).
> >
> >
> Would you please do again your benchmarks with any data type of your choice
> besides char? For instance longs, or floats? Or doubles, or pairs of
> whatever?
> Long long? If I understand well the machinery for chars you get the maximum
> improvement: tuning on that case would amount to consider std::vector<char>
> the most common instantiation...
Yes, I have attached a file containing the test results.
>
> Paolo.
--
-Dhruv Matani.
http://www.geocities.com/dhruvbird/
The price of freedom is responsibility, but it's a bargain, because
freedom is priceless. ~ Hugh Downs
-------------- next part --------------
Using std::string
=================
Without the optimization(using __mt_alloc)
------------------------------------------
[dhruv@localhost test]$ g++40 -Wall -O3 vec_expand.cpp
[dhruv@localhost test]$ time ./a.out
4, 17
Copy ctor called: 14700000 times.
Destructor called: 19500000 times.
real 0m5.234s
user 0m5.200s
sys 0m0.000s
With the optimization(using std::allocator)
-------------------------------------------
[dhruv@localhost test]$ g++40 -Wall -O3 vec_expand.cpp
[dhruv@localhost test]$ time ./a.out
4, 17
Copy ctor called: 9600000 times.
Destructor called: 14400000 times.
real 0m4.189s
user 0m4.150s
sys 0m0.010s
Using std::vector<int>(1024)
============================
Without the optimization(using __mt_alloc)
------------------------------------------
[dhruv@localhost test]$ g++40 -Wall -O3 vec_expand.cpp
[dhruv@localhost test]$ time ./a.out
12, 6
Copy ctor called: 4800000 times.
Destructor called: 6300000 times.
real 0m30.253s
user 0m29.770s
sys 0m0.010s
With the optimization(using std::allocator)
-------------------------------------------
[dhruv@localhost test]$ g++40 -Wall -O3 vec_expand.cpp
[dhruv@localhost test]$ time ./a.out
12, 6
Copy ctor called: 3000000 times.
Destructor called: 4500000 times.
real 0m25.794s
user 0m25.710s
sys 0m0.000s
Using float
===========
Without the optimization(using __mt_alloc)
------------------------------------------
[dhruv@localhost test]$ g++40 -Wall -O3 vec_expand.cpp
[dhruv@localhost test]$ time ./a.out
4, 17
Copy ctor called: 14700000 times.
Destructor called: 19500000 times.
real 0m0.321s
user 0m0.300s
sys 0m0.000s
With the optimization(using std::allocator)
-------------------------------------------
[dhruv@localhost test]$ g++40 -Wall -O3 vec_expand.cpp
[dhruv@localhost test]$ time ./a.out
4, 17
Copy ctor called: 9600000 times.
Destructor called: 14400000 times.
real 0m0.169s
user 0m0.150s
sys 0m0.000s
More information about the Libstdc++
mailing list