.NET Sorted Dictionary vs. PTL Map32 – Add, Item & Remove Functions

Our latest Parallel Template Library (PTL) video demonstrates the performance of PTL’s map container, Map32, for large data sets by comparing it to the equivalent .NET SortedDictionary container.

During the demo, we add, retrieve and remove 100 million elements (which consist of a key and a value) from both map containers on a system with a quad-core processor and 32 GB of memory. PTL’s Map32 inserted elements 3.8 times faster, retrieved elements 2.1 times faster and erased elements 2.8 times faster than .NET’s SortedDictionary.

A map is a variable-sized collection of (key, value) pairs. Its primary usage is the efficient retrieval of elements (or values) based on their associated keys. It also implements the insertion and removal of elements very efficiently.

PTL offers Map32 and Map64 classes that are very similar to the .NET SortedDictionary class. PTL maps differ from the .NET SortedDictionary because they have a Boolean property called “Unique” that is set in their constructor and indicates if the map allows or disallows duplicate keys. The .NET SortedDictionary only allows elements with unique keys. It’s also important to note that PTL’s Map32 and Map64 are not tuned for a 32 or 64-bit operating system; they only differ in their maximum size.

For this demo, we use the .NET SortedDictionary and the PTL Map32 containers. Both containers are filled with MapEntry values, which are (key, value) pairs. The size of a MapEntry object is 16 bytes (8 bytes for the key and 8 bytes for the value).

To fill both containers with values, we use a randomly-shuffled array of 100 million numbers that has been stored to a file. We use this same file to load both the .NET SortedDictionary and PTL Map32 objects with MapEntry values, and we use the next random number for both the key and the value for each MapEntry element. This allows us to compare the results using the exact same data.

First in the demo, we add 100 million elements to an empty .NET SortedDictionary object using its Add method. Next, while we still have the dictionary in memory, we retrieve all of the values based on the key using its Item property. We read the keys from the same file that we used for insertion. Finally, we remove all of the elements from the dictionary in the same order that we inserted them using its Remove method.

Next, we run the same three tests for a PTL Map32 object using its Insert method, Item property and Erase method. The Insert method of the PTL Map32 finished in 1 minute and 47 seconds with an average speed of 934,579 elements per second, and it was 3.8 times faster than the Add method of the .NET SortedDictionary. The Item property of the Map32 retrieved all of the elements in 1 minute and 11 seconds with an average speed of 1,408,450 elements per second, which was 2.1 times faster than the Item property of the SortedDictionary. Finally, the Erase method of the Map32 finished in 1 minute and 26 seconds with an average speed of 1,162,790 elements per second, which was 2.8 times faster than the Remove method of the SortedDictionary.

.NET SortedDictionary vs. PTL Map32

These tests demonstrate that the PTL map classes are well designed to sustain large datasets and its insert, retrieve and erase functions have much faster performance than the equivalent .NET functions.

If you’re ready to test PTL’s containers for yourself, you can download our free trials for .NET or Java. Stay tuned for more map demos coming soon, and please let us know what other function demos or tutorials you would like to see next.

LinkedInGoogle+TwitterFacebookGoogle GmailShare

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>