Example #1
0
        private void TestCache(DoubleBarrelLRUCache <CloneableInteger, object> cache, int n)
        {
            object dummy = new object();

            for (int i = 0; i < n; i++)
            {
                cache.Put(new CloneableInteger(i), dummy);
            }

            // access every 2nd item in cache
            for (int i = 0; i < n; i += 2)
            {
                Assert.IsNotNull(cache.Get(new CloneableInteger(i)));
            }

            // add n/2 elements to cache, the ones that weren't
            // touched in the previous loop should now be thrown away
            for (int i = n; i < n + (n / 2); i++)
            {
                cache.Put(new CloneableInteger(i), dummy);
            }

            // access every 4th item in cache
            for (int i = 0; i < n; i += 4)
            {
                Assert.IsNotNull(cache.Get(new CloneableInteger(i)));
            }

            // add 3/4n elements to cache, the ones that weren't
            // touched in the previous loops should now be thrown away
            for (int i = n; i < n + (n * 3 / 4); i++)
            {
                cache.Put(new CloneableInteger(i), dummy);
            }

            // access every 4th item in cache
            for (int i = 0; i < n; i += 4)
            {
                Assert.IsNotNull(cache.Get(new CloneableInteger(i)));
            }
        }
Example #2
0
            public override void Run()
            {
                try
                {
                    long count = 0;
                    long miss  = 0;
                    long hit   = 0;
                    int  limit = objs.Length;

                    while (true)
                    {
                        CloneableObject obj = objs[(int)((count / 2) % limit)];
                        object          v   = c.Get(obj);
                        if (v == null)
                        {
                            c.Put(new CloneableObject(obj), obj);
                            miss++;
                        }
                        else
                        {
                            Assert.True(obj == v);
                            hit++;
                        }
                        if ((++count % 10000) == 0)
                        {
                            if (DateTime.Now.CompareTo(endTime) > 0)
                            {
                                break;
                            }
                        }
                    }

                    outerInstance.AddResults(miss, hit);
                }
                catch (Exception t)
                {
                    failed = true;
                    throw new Exception(t.Message, t);
                }
            }
Example #3
0
            public override void Run()
            {
                try
                {
                    long count = 0;
                    long miss  = 0;
                    long hit   = 0;
                    int  limit = objs.Length;

                    while (true)
                    {
                        CloneableObject obj = objs[(int)((count / 2) % limit)];
                        object          v   = c.Get(obj);
                        if (v == null)
                        {
                            c.Put(new CloneableObject(obj), obj);
                            miss++;
                        }
                        else
                        {
                            Assert.True(obj == v);
                            hit++;
                        }
                        if ((++count % 10000) == 0)
                        {
                            if (J2N.Time.NanoTime() / J2N.Time.MillisecondsPerNanosecond > endTime) // LUCENENET: Use NanoTime() rather than CurrentTimeMilliseconds() for more accurate/reliable results
                            {
                                break;
                            }
                        }
                    }

                    outerInstance.AddResults(miss, hit);
                }
                catch (Exception t) when(t.IsThrowable())
                {
                    failed = true;
                    throw RuntimeException.Create(t);
                }
            }