Sorted map vs hashed map

In theory, hash map structure should be very fast on retrieving by key operations, close to O(1) like for an array. A sorted map (keys are sorted) should be O(log2 N) instead. The following test checks the difference.

Common scenario

We will use one tester class per type of tested structure. The keys are string[10] and are generated randomly in prepared array to avoid additional checks whether the key exists or not.

Free Pascal bencmark: array vs TList vs dynamic array

Let's make a simple benchmark test for random and sequential access. I will compare:

  • array with predefined size (allocated on stack)
  • TList container class (allocated on heap)
  • dynamic array (allocated on heap)
  • generic TFPGList (allocated on heap)

I use an array of 10M elements having integer and varaint data type. You can easily change its type definition in "type" section if need.

Subscribe to RSS - Testing