Exemple #1
0
        public void SerializeDeserializeTest()
        {
            XS1_DataObject start = new XS1_DataObject("server","Keller", ObjectTypes.Sensor, "temperature", new DateTime(2010, 12, 18, 17, 37, 31, 0, System.Globalization.Calendar.CurrentEra), 1, 14.8);
            byte[] Serialized;
            XS1_DataObject deserialized;

            Serialized = start.Serialize();

            deserialized = new XS1_DataObject();
            deserialized.Deserialize(Serialized);

            Assert.AreEqual(start.ServerName, deserialized.ServerName);
            Assert.AreEqual(start.Name,             deserialized.Name);
            Assert.AreEqual(start.Timecode.Ticks,   deserialized.Timecode.Ticks);
            Assert.AreEqual(start.Type,             deserialized.Type);
            Assert.AreEqual(start.TypeName,         deserialized.TypeName);
            Assert.AreEqual(start.Value,            deserialized.Value);
            Assert.AreEqual(start.XS1ObjectID,      deserialized.XS1ObjectID);

            start = new XS1_DataObject("server","Keller", ObjectTypes.Actor, "temperature", new DateTime(2010, 12, 18, 17, 37, 31, 0, System.Globalization.Calendar.CurrentEra), 1, 14.8);

            Serialized = start.Serialize();

            deserialized = new XS1_DataObject();
            deserialized.Deserialize(Serialized);

            Assert.AreEqual(start.ServerName, deserialized.ServerName);
            Assert.AreEqual(start.Name, deserialized.Name);
            Assert.AreEqual(start.Timecode.Ticks, deserialized.Timecode.Ticks);
            Assert.AreEqual(start.Type, deserialized.Type);
            Assert.AreEqual(start.TypeName, deserialized.TypeName);
            Assert.AreEqual(start.Value, deserialized.Value);
            Assert.AreEqual(start.XS1ObjectID, deserialized.XS1ObjectID);
        }
Exemple #2
0
		static void Main(string[] args)
		{
			Console.WriteLine("hacs storage performance tuning project: benchmark");
			Console.WriteLine("(C) 2013 Daniel Kirstenpfad - http://technology-ninja.com");
			Console.WriteLine();

			int number = 100000;
			int cachefactor = 1;
			Stopwatch sw = new Stopwatch();

			#region Generating benchmark data set
			if (Directory.Exists("benchmark-data"))
			{
				Directory.Delete("benchmark-data",true);
				Directory.CreateDirectory("benchmark-data");
			}
			else
				Directory.CreateDirectory("benchmark-data");
			sw.Start();
			TinyOnDiskStorage benchmark_storage = new TinyOnDiskStorage("benchmark-data" + Path.DirectorySeparatorChar + "benchmark-data", false, number/cachefactor);
			sw.Stop();
			Console.WriteLine("Initialized benchmark-data storage in "+sw.ElapsedMilliseconds+" ms");

			sw.Reset();

			Console.Write("Generating data ("+number+") - ");

			int CursorLeft = Console.CursorLeft;
			int CursorTop = Console.CursorTop;

			sw.Start ();
			for (int i=0;i<=number;i++)
			{
				//Console.SetCursorPosition(CursorLeft,CursorTop);
				//Console.Write(i+"/"+number);

				// now generating the file...
				XS1_DataObject data = new XS1_DataObject("ServerName","Name",ObjectTypes.Actor,"TypeName",DateTime.Now,i,i);

				benchmark_storage.Write(data.Serialize());
			}
			sw.Stop();
			Console.WriteLine("done in "+sw.ElapsedMilliseconds+" ms");

			sw.Reset();
			Console.WriteLine("Resetting...");

			benchmark_storage.Shutdown();

			sw.Start();
			benchmark_storage = new TinyOnDiskStorage("benchmark-data" + Path.DirectorySeparatorChar + "benchmark-data", false, number/2);
			sw.Stop();
			Console.WriteLine("Initialized benchmark-data storage in "+sw.ElapsedMilliseconds+" ms");
			sw.Reset();

			Console.Write("Reading ("+number+") - ");
			int o = 0;
			sw.Start();
			foreach(OnDiscAdress addr in benchmark_storage.InMemoryIndex)
			{
				XS1_DataObject data = new XS1_DataObject();
				data.Deserialize(benchmark_storage.Read(addr));
				if (data.XS1ObjectID != o)
					Console.WriteLine(data.Timecode.ToString());
				o++;
			}
			o--;
			sw.Stop();
			Console.WriteLine("done ("+o+") in "+sw.ElapsedMilliseconds+" ms");
			sw.Reset();
			#endregion
		}