ptlib  2.12.8
About: ptlib (Portable Windows Libary) offers a method to product applications to let run on both Microsoft Windows and Unix X-Windows systems.
  Fossies Dox: ptlib-2.12.8-src.zip  ("inofficial" and yet experimental doxygen-generated source code documentation)  

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
map_dictionary

The purpose of this program is to find out which is faster:

  • STL based map
  • PTLib based dictionary

By default, this program creates the 200 instances of the structure Element. Each instance of the Element class is given a random (and hopefully) unique key. The key can exist either as a string, or as a number.

Each instance of the class Element has a key to the next instance.

After creation of an instance of the class Element, it is put into a map (or PDictionary), keyed of the random key.

Then, the code looks through the map (or PDictionary) for each created instance. Since the code knows the first key, it can get the key of the next element via the current element. In this way, the code is made to make N acceses to seemingly random parts of the map (or PDictionary).

Results so far:

Running 100000 lookups, 10000 iterates, over map/dictionary with 20 elements. Structure Insert Lookup Iterate Remove String Map 0:00.000 0:00.964 0:00.515 0:00.000 String Dictionary 0:00.000 0:00.140 0:00.666 0:00.000 Integer Map 0:00.000 0:00.603 0:00.514 0:00.000 Integer Dictionary 0:00.000 0:00.121 0:00.364 0:00.000

Running 50000 lookups, 5000 iterates, over map/dictionary with 100 elements. Structure Insert Lookup Iterate Remove String Map 0:00.002 0:00.647 0:01.246 0:00.004 String Dictionary 0:00.000 0:00.095 0:01.061 0:00.000 Integer Map 0:00.002 0:00.359 0:01.252 0:00.002 Integer Dictionary 0:00.001 0:00.061 0:00.816 0:00.001

Running 50000 lookups, 2000 iterates, over map/dictionary with 500 elements. Structure Insert Lookup Iterate Remove String Map 0:00.018 0:00.797 0:02.507 0:00.026 String Dictionary 0:00.009 0:00.065 0:01.843 0:00.014 Integer Map 0:00.018 0:00.430 0:02.505 0:00.017 Integer Dictionary 0:00.021 0:00.284 0:01.566 0:00.015

Running 20000 lookups, 500 iterates, over map/dictionary with 2000 elements. Structure Insert Lookup Iterate Remove String Map 0:00.054 0:00.422 0:02.525 0:00.182 String Dictionary 0:00.122 0:00.079 0:01.786 0:00.168 Integer Map 0:00.137 0:00.180 0:02.574 0:00.099 Integer Dictionary 0:00.249 0:00.314 0:01.542 0:00.166

Running 10000 lookups, 100 iterates, over map/dictionary with 10000 elements. Structure Insert Lookup Iterate Remove String Map 0:00.299 0:00.244 0:02.597 0:01.621 String Dictionary 0:00.287 0:00.280 0:01.853 0:02.135 Integer Map 0:00.158 0:00.099 0:02.573 0:01.166 Integer Dictionary 0:01.125 0:00.700 0:01.612 0:01.764

Running 5000 lookups, 50 iterates, over map/dictionary with 50000 elements. Structure Insert Lookup Iterate Remove String Map 0:01.691 0:00.115 0:06.581 0:08.311 String Dictionary 0:06.516 0:00.544 0:04.878 0:10.517 Integer Map 0:00.921 0:00.050 0:06.562 0:06.710 Integer Dictionary 0:22.441 0:01.899 0:04.348 0:10.303

So, depending on which parameter is most importaint, there are different thresholds. So how many elements are required in a dictionary before you should switch to a map:

Structure Insert Lookup Iterate Remove String Keys 5,000 10,000 Never! 5,000 Integer Keys 1,000 10.000 Never! 1,000