Feature Post

Breaking News

Persistent Dictionary

Key Features:
A data structure implementation similar to Dictionary in .NET.
- Writes objects to file system to preserve the memory
- Hold keys/locations in memory
- Retrieves any object by passing key in less than five milliseconds
Output, with 10000 inserts/updates/deletes:
image
Memory profiling:
image
   1: using (CPersistentDictionary lst = new CPersistentDictionary(@"C:\persist.kkhan"))
   2: {
   3:     Stopwatch timer = new Stopwatch();
   4:  
   5:     //1. Insert/update items
   6:  
   7:     int threshold = 10000;
   8:     timer.Start();
   9:     for (int i = 0; i < threshold; i++)
  10:     {
  11:         lst.Add("Counter" + i.ToString(), i.ToString());
  12:     }
  13:     timer.Stop();
  14:     Console.WriteLine("Items processed(add):{0}", threshold);
  15:     Console.WriteLine("Time elapsed in (ms):{0}  ({1} secs)", timer.ElapsedMilliseconds, TimeSpan.FromMilliseconds(timer.ElapsedMilliseconds).Seconds);
  16:  
  17:  
  18:     //2. Read items
  19:     timer.Start();
  20:     for (int i = 0; i < threshold; i++)
  21:     {
  22:         var o = lst["Counter" + i.ToString()];
  23:     }
  24:     timer.Stop();
  25:     Console.WriteLine("Items processed(read):{0}", threshold);
  26:     Console.WriteLine("Time elapsed in (ms):{0}  ({1} secs)", timer.ElapsedMilliseconds, TimeSpan.FromMilliseconds(timer.ElapsedMilliseconds).Seconds);
  27:  
  28:  
  29:     //3. Remove items
  30:     timer.Start();
  31:     for (int i = 0; i < threshold; i++)
  32:     {
  33:         lst.Remove("Counter" + i.ToString());
  34:     }
  35:     timer.Stop();
  36:     Console.WriteLine("Items processed(Remove):{0}", threshold);
  37:     Console.WriteLine("Time elapsed in (ms):{0}  ({1} secs)", timer.ElapsedMilliseconds, TimeSpan.FromMilliseconds(timer.ElapsedMilliseconds).Seconds);
  38:  
  39:  
  40:  
  41:     Console.ReadKey();
  42: }

 http://persistentdictionary.codeplex.com

3 comments:

  1. Hi

    I read this two times.
    I like it so much ,try to keep posting.

    regards

    Business Dictionary

    ReplyDelete
  2. Got an email from Alex says: "I am trying to use the presistentDictionary class that you published. There seems to be a problem that the database file is kept well, but the index file has the size of zero all the time. so it doesn't behave as expected I Think. Can you help with this? or if u want I can alter it and change the code to save the index file somehow..."

    Answer: Alex my friend, if you look at the Test Unit, it Add(), it Reads(), and it Removes() all the values, therefore index will always be zero, given the test unit. Comment the line 33 (lst.Remove) in the code snippet above and you will see the index file growing.

    ReplyDelete