Opened 9 years ago

Closed 8 years ago

#9637 closed Bugs (fixed)

Boost.Container vector::resize() performance issue

Reported by: Dariush Forouher <dariush@…> Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: container
Version: Boost 1.55.0 Severity: Optimization
Keywords: Cc:

Description

Hi,

I noticed that resize() on a boost vector is quite slow compared to the equivalent operation on a std::vector:

int size=2000000;

std::vector<char, std::allocator<char> > vec;
vec.resize(size); // ~500 us

boost::container::vector<char, std::allocator<char> > vec2;
vec2.resize(size); // ~3000 us

I've attached a test program, compiled with "g++ -O3 -o test test.cpp"

Environment:

  • gcc version 4.6.4 (Ubuntu/Linaro 4.6.4-1ubuntu1~12.04)
  • boost 1.55.0

(Side note: the performance is even worse when compiled with -O0).

cheers Dariush

Attachments (1)

test.cpp (911 bytes ) - added by Dariush Forouher <dariush@…> 9 years ago.

Download all attachments as: .zip

Change History (2)

by Dariush Forouher <dariush@…>, 9 years ago

Attachment: test.cpp added

comment:1 by Ion Gaztañaga, 8 years ago

Resolution: fixed
Status: newclosed

Thanks for the report. libstdc++ was using memset to initialize the array of chars. In commit (master and develop branches):

SHA-1: 5afad7cd0c5512016f9ad60e03c95e84a470ce17

  • Added optimization for types that can be value initialized with memset.

Boost.Container uses memset with zero value to initialize several types including "char" values.

Note: See TracTickets for help on using tickets.