Granville Barnett

Profiling some data structures

I don't know why but I randomly decided to see how well my SinglyLinkedListCollection<T> fared against the LinkedList<T> collection in System.Collections.Generic.

First off, my implementation supports pretty much everything that the MS LinkedList<T> does, that includes full LINQ support and so on.

Anyway, I added 5000 items to each to see what that would do - I actually expected the BCL data structure to be superior to mine.  I had done no real magic in my implementation, I had simply coded the thing after working out the various algorithms on paper.

Memory allocation:  both data structures are allocated 48 bytes total per instance, however I can only assume that the node used internally by the BCL collection has maybe another pointer i.e. it has a next and prev pointer, giving the ability to use it as a DoublyLinkedList? (I've not looked at it yet).  This is where my implementation kind of wins, although I'm pretty sure at this moment that the BCL node supports doubly linked list style structures - in any case as my node is smaller than that of the BCL one my implementation after 5000 instances are created totals 160,000 bytes, the BCL one on the other hand stands at 240,000 bytes so quite a reduction there.

FYI: my node size is 32 bytes, the BCL one is 48 bytes.

sllVll

Out of curiosity I also benchmarked my DoublyLinkedListCollection<T> against the LinkedList<T> of the BCL and my node size is still smaller, this time only by 8 bytes per instance but it still add's up.  Same scenario, 5000 items added my implementation has been allocated 200,000 bytes where as the BCL one has been allocated 240,000 bytes - still a considerable saving, all be it slightly less.

dllVll

Again, the actual data structures were allocated 48 bytes.

If you want to rip my implementations to bits then you can go ahead and download it from here: DSA 0.2.2 (you shouldn't notice any difference between these implementations and the BCL ones - both in terms of API and design time debugging experiences).

Comments

No Comments