Tuesday, April 19, 2011

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

2 comments:

  1. Nice blog and thanks share with u s.
    Business Dictionary

    ReplyDelete
  2. Hi

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

    regards

    Business Dictionary

    ReplyDelete

Related Posts

Popular Posts