예제 #1
0
        public void StoreAndRetrieve()
        {
            var world = new RecordedMapModel <string, EntityModel>();
            var foo   = new EntityModel(1, "Rich", "bar.3ds", new Vector3D(0, 0, 0), Quaternion.Identity);
            var bar   = new EntityModel(2, "Ada", "bar.3ds", new Vector3D(1, 1, 1), Quaternion.Identity);

            world.Set(foo.Name, foo);
            world.Set(bar.Name, bar);
            Assert.AreEqual(0, world.Get(foo.Name).Position.X);
            world.Set(foo.Name, new EntityModel(1, foo.Name, foo.ModelId, new Vector3D(2, 2, 2), Quaternion.Identity));
            Assert.AreEqual(2, world.Get(foo.Name).Position.X);
            Assert.AreEqual(3, world.CurrentVersion);
        }
예제 #2
0
        public void Performance()
        {
            //Var.pushThreadBindings(RT.map(RT.CURRENT_NS, RT.CURRENT_NS.deref()));
            var m1 = new RecordedMapModel<string, Item>();
            //var m2 = new ClojureRecordedMapModel<string, Item>();
            var m3 = new Dictionary<string, Item>();
            var m4 = new FSharpMap<string, Item>(Enumerable.Empty<Tuple<string, Item>>());
            //var m5 = new PersistentTreeMap();

            const int size = 10000;
            var s = new Stopwatch();
            s.Start();
            for (var i = 0; i < size; i++)
                m1.Set(i.ToString(), new Item(i, i.ToString()));
            for (var i = 0; i < size * 100; i++)
                m1.Get((i % size).ToString());
            for (var i = 0; i < size; i++)
                m1.Remove(i.ToString());
            s.Stop();
            Console.WriteLine("RecordedMapModel took " + s.Elapsed);

            /*
            s.Restart();
            for (var i = 0; i < size; i++)
                m2.Set(i.ToString(), new Item(i, i.ToString()));
            for (var i = 0; i < size * 100; i++)
                m2.Get((i % size).ToString());
            for (var i = 0; i < size; i++)
                m2.Remove(i.ToString());
            s.Stop();
            Console.WriteLine("ClojureRecordedMapModel took " + s.Elapsed);
             */

            s.Restart();
            for (var i = 0; i < size; i++)
                m3[i.ToString()] = new Item(i, i.ToString());
            Item o;
            for (var i = 0; i < size * 100; i++)
                m3.TryGetValue((i % size).ToString(), out o);
            for (var i = 0; i < size; i++)
                m3.Remove(i.ToString());
            s.Stop();
            Console.WriteLine("Dictionary took " + s.Elapsed);

            m3.Clear();
            s.Restart();
            for (var i = 0; i < size; i++)
            {
                var tmp = new Dictionary<string, Item>(m3);
                tmp[i.ToString()] = new Item(i, i.ToString());
                m3 = tmp;
            }
            for (var i = 0; i < size * 100; i++)
                m3.TryGetValue((i % size).ToString(), out o);
            for (var i = 0; i < size; i++)
            {
                var tmp = new Dictionary<string, Item>(m3);
                tmp.Remove(i.ToString());
                m3 = tmp;
            }
            s.Stop();
            Console.WriteLine("Copy Dictionary took " + s.Elapsed);

            s.Restart();
            for (var i = 0; i < size; i++)
                m4 = m4.Add(i.ToString(), new Item(i, i.ToString()));
            for (var i = 0; i < size * 100; i++)
                m4.TryFind((i % size).ToString());
            for (var i = 0; i < size; i++)
                m4 = m4.Remove(i.ToString());
            s.Stop();
            Console.WriteLine("FSharpMap took " + s.Elapsed);

            /*
            s.Restart();
            for (var i = 0; i < size; i++)
                m5 = (PersistentTreeMap)m5.assoc(i.ToString(), new Item(i, i.ToString()));
            object obj;
            for (var i = 0; i < size * 100; i++)
                m5.TryGetValue((i % size).ToString(), out obj);
            for (var i = 0; i < size; i++)
                m5 = (PersistentTreeMap)RT.dissoc(m5, i.ToString());
            s.Stop();
            Console.WriteLine("PersistentTreeMap took " + s.Elapsed);
             */
        }