MarsJupiter - Family shareware  
 
 Monday, 01 December 2008
Benchmarking the standard template library STL
Page 1 of 12

Introduction

Given the rich provision of normal and template classes in MFC, it is common for programmers in Visual C++ to ignore the standard template library.

vector and CPtrArray

These are the two most easily compared array classes and we ran a simple benchmark test adding 100,000 and 200,000 objects to the end of an array, then individually removing the objects from the start of the array.

We also included in the test, as a point of thoroughness, the CEzArray class used in some marsjupiter.com projects as a lightweight array class for arrays with less than an unsigned short number of elements, obviously we modified this to allow for the large number of elements in the test. Since we never layed any great claims for CEzArray in terms of efficiency we were expecting it to come last. 

Array Type 100,000 members 200,000 members
vector 7.98 secs 65.06 secs
CPtrArray 8.03 secs 65.24 secs
CEzArray 8.25 secs 64.98 secs

The results were interestingly close for all array types, with a clear non linear degradation in performance with the increase in members. On analysis the reason they are all close is that the vast bulk of the time is taken up with deletion. This comes down to constant memory shifting and no class can have any special cleverness for this.

Repeating the test with larger numbers allocated, but removing all deletions from the test:

 

Array Type 2000,000 members 4000,000 members
vector 0.75 secs 1.55 secs
CPtrArray 22.23 secs 84.95 secs
CEzArray 22.2 secs 88.03 secs

Here is is apparent that the time differences are huge and are to do with the reallocation strategies of the different array types. Each time an element is added to an array, the array makes space not only for the element added, but it should also make a guess at how many more elements are likely to be added. This avoids constant memory reallocation and it seems from these tests that vector wins hands down.

Of course more testing might reveal the exception that proves the rule and the more liberal allocation strategy of vector might is some circumstances allocate an excess of memory.



 
Products

Callisto - Newsreader/Bulletin Board Browser. The best way to
browse usenet and bulletin boards.
Newsreader/BBS Browser


Foboz - Meta Search Engine, The best Meta Search Engine, searching
hundreds of search engines from the best sites across the web.
Meta Search Engine


 

ThereIWas - Intelligent Favorites/History Toolbar for internet
Explorer
Favorites/History Toolbar


 

WhereWasi? - History Word Search Toolbar for Internet Explorer
History Word Search Toolbar

Main Menu
Home
MarsJupiter Products
Callisto Newsreader - News Reader/Forum Browser
Foboz Meta Search Engine - Unbeatable Results
Where Was I?
ThereIWas - intelligent history/favorites
UpFront - Ingres FRS GUI
Company News
Contact Us
FAQ
MarsJupiter Forums
Affiliate Programme
Alex Programming
Resources
The Web Links
The Daily Blat
Newsflash
Current Releases
Callisto News Reader/Bulletin Board Browser 3.14 has now been released:
Download Callisto here
Tucows rating:
Foboz Meta Search Engine 1.52 has been released:
Download Foboz here
Tucows rating:
WhereWAsI? - Internet Explorer history search toolbar 1.50 has been released:
Download WhereWasI? here
AuntyJean - Internet Explorer family friendly Filter toolbar 1.00 has been released:
Download AuntyJean here
ThereIWas- Intelligent Favorites/history Internet Explorer toolbar 1.02 has been released:
Download ThereIWas here
Coop Ad Link Module
Loans|Credit Card|Electricity Suppliers|Fantasy Football|Mobile Phones
 
Go to top of page  Home | MarsJupiter Products | Callisto Newsreader - News Reader/Forum Browser | Foboz Meta Search Engine - Unbeatable Results | Where Was I? | ThereIWas - intelligent history/favorites | UpFront - Ingres FRS GUI | Company News | Contact Us | FAQ | MarsJupiter Forums | Affiliate Programme | Alex Programming | Resources | The Web Links | The Daily Blat |