public void BenchmarkSerializeMethod <T>(ISerializeDeserialize <T> serializer, object instance) { serializer.ObjectToBytes((T)instance); Stopwatch timed = new Stopwatch(); timed.Start(); byte[] bytes = null; for (int x = 0; x < Iterations; x++) { bytes = serializer.ObjectToBytes((T)instance); } timed.Stop(); Trace.WriteLine("Serialize method: " + serializer.GetType().Name); Trace.WriteLine(timed.ElapsedMilliseconds + " ms"); Trace.WriteLine("Data size: " + bytes.Length); Trace.WriteLine(""); }
public void BenchmarkDeserializeMethod <T>(ISerializeDeserialize <T> serializer, object instance) { var bytes = serializer.ObjectToBytes((T)instance); serializer.BytesToObject(bytes); Stopwatch timed = new Stopwatch(); timed.Start(); T value = default(T); for (int x = 0; x < Iterations; x++) { value = serializer.BytesToObject(bytes); } timed.Stop(); Trace.WriteLine("Deserialize method: " + serializer.GetType().Name); Trace.WriteLine(timed.ElapsedMilliseconds + " ms"); Trace.WriteLine(value); Trace.WriteLine(""); }
private void InitializeControlFile() { if (File.Exists(_controlFile)) { if (!File.Exists(_hashFile)) { throw new FileNotFoundException("Hash file is missing"); } if (!File.Exists(_keyFile)) { throw new FileNotFoundException("Key file is missing"); } if (!File.Exists(_valueFile)) { throw new FileNotFoundException("Value file is missing"); } string[] settings = File.ReadAllLines(_controlFile); int ctrlCapacity = int.Parse(settings[0]); if (ctrlCapacity != _capacity) { throw new ArgumentException("capacity differes from existing file. " + _capacity + " != " + ctrlCapacity); } //TODO: iterate over serializers and compare on name - create method on the factory _keySerializer = _keyFactory.GetSerializer(settings[1]); if (_keySerializer == null) { throw new InvalidOperationException("Could not find serializer: " + settings[1]); } _valueSerializer = _valueFactory.GetSerializer(settings[2]); if (_valueSerializer == null) { throw new InvalidOperationException("Could not find serializer: " + settings[2]); } } else { if (File.Exists(_hashFile)) { throw new InvalidOperationException("Hash file exists already"); } if (File.Exists(_keyFile)) { throw new FileNotFoundException("Key file exists already"); } if (File.Exists(_valueFile)) { throw new FileNotFoundException("Value file exists already"); } using (var fileStream = File.CreateText(_controlFile)) { fileStream.WriteLine(_capacity.ToString()); fileStream.WriteLine(_keySerializer.GetType().AssemblyQualifiedName); fileStream.WriteLine(_valueSerializer.GetType().AssemblyQualifiedName); } } }