예제 #1
0
파일: ContainersTest.cs 프로젝트: mo5h/omeo
        public void TestCacheEnumerator()
        {
            IntObjectCache cache = new IntObjectCache(16);

            for (int i = 0; i < 10; ++i)
            {
                cache.CacheObject(i, i);
            }
            int count = 0;

            foreach (int i in cache)
            {
                ++count;
            }
            Assert.AreEqual(10, count);
            for (int i = 0; i < 10; ++i)
            {
                cache.CacheObject(i + 10, i);
            }
            count = 0;
            foreach (int i in cache)
            {
                ++count;
            }
            Assert.AreEqual(cache.Size, count);
        }
예제 #2
0
 static IntInternalizer()
 {
     _intCacheLock = new SpinWaitLock();
     _intCache     = new IntObjectCache(_intCacheSize);
     for (int i = 0; i < _intCacheSize; ++i)
     {
         _intCache.CacheObject(i, i);
     }
 }
예제 #3
0
파일: ContainersTest.cs 프로젝트: mo5h/omeo
        public void StressCaching()
        {
            const int      cacheSize = 1000;
            IntObjectCache cache     = new IntObjectCache(cacheSize);
            Random         rnd       = new Random();

            for (int i = 0; i < 100000000; ++i)
            {
                int next = rnd.Next(cacheSize * 2);
                if (cache.TryKey(next) == null)
                {
                    cache.CacheObject(next, i);
                }
            }
            Console.WriteLine("Cache hit rate = " + cache.HitRate().ToString());
        }