static void SafeTest() { System.IO.File.WriteAllBytes(System.Environment.CurrentDirectory + "\\a.txt", new byte[0]); StreamLoger.Stream = System.IO.File.Open(Environment.CurrentDirectory + "\\DebugLog", System.IO.FileMode.OpenOrCreate); Ar = new StreamCollection <TestClass>(); Ar.Collection.Stream = System.IO.File.Open(Environment.CurrentDirectory + "\\a.txt", System.IO.FileMode.Truncate); s: var Role = random.Next(0, 5); switch (Role) { case 0: { var Pos = random.Next(0, Ar.Length); var Data = new TestClass() { Bytes = new byte[random.Next(0, 50)] }; Data.count = Data.Bytes.Length; StreamLoger.run(() => { Ar.Insert(Data, Pos); var OldData = Ar[Pos]; if (OldData.count != Data.count | OldData.Bytes.Length != Data.Bytes.Length) { throw new Exception(); } }); } break; case 1: if (Ar.Length > 0) { var Pos = random.Next(0, Ar.Length - 1); var Data = new TestClass() { Bytes = new byte[random.Next(0, 50)] }; Data.count = Data.Bytes.Length; StreamLoger.run(() => { Ar[Pos] = Data; var OldData = Ar[Pos]; if (OldData.count != Data.count | OldData.Bytes.Length != Data.Bytes.Length) { throw new Exception(); } }); } break; case 2: if (Ar.Length > 0) { var Pos = random.Next(0, Ar.Length); StreamLoger.run(() => { var InnerData = Ar[Pos]; }); } break; case 3: if (Ar.Length > 0) { var Pos = random.Next(0, Ar.Length - 1); StreamLoger.run(() => { Ar.DeleteByPosition(Pos); }); } break; case 4: StreamLoger.run(() => { var newar = Ar.Serialize().Deserialize(Ar); //newar.Info.Browse(newar); }); break; } goto s; }
static void PerformanceTest() { System.IO.File.WriteAllBytes(System.Environment.CurrentDirectory + "\\a.txt", new byte[0]); var FileStream = System.IO.File.Open(System.Environment.CurrentDirectory + "\\a.txt", System.IO.FileMode.Truncate); var MemoryStream = new System.IO.MemoryStream(); var Sr = new List <int>(); var Stream = new StreamCollection <int>(FileStream); //// warm up Stream.Insert(0); Stream.DeleteByPosition(0); var Count = 1_000_000; var InsertTime = Timing.run(() => { for (int i = 0; i < Count; i++) { Stream.Insert(i, i); } }); var Inserts_Per_Second = (int)(Count / InsertTime.TotalSeconds); var EveryInsert = (InsertTime.TotalSeconds / Count).ToString("0.##########"); var EveryInsert_Milisecond = ((InsertTime.TotalSeconds / Count) * 1000).ToString("0.##########"); var UpdateTime = Timing.run(() => { for (int i = 0; i < Count; i++) { Stream[i] = i; } }); var Update1_Per_Second = (int)(Count / UpdateTime.TotalSeconds); var GetTimeByPosition = Timing.run(() => { for (int i = 0; i < Count; i++) { var c = Stream[i]; if (c == null) { throw new Exception(); } } }); var Get_Position_Per_Second = (int)(Count / GetTimeByPosition.TotalSeconds); var DeleteTime = Timing.run(() => { for (int i = 0; i < Count; i++) { Stream.DeleteByPosition(0); } }); var Delete_Per_Second = (int)(Count / DeleteTime.TotalSeconds); }