public void RegexNewlineNormalizerTest() { CodeTimer.WarmUp(); var sb = new StringBuilder(); int length = (1024 * 1024) / sizeof(char); string[] words = { "Dummy", "\r", "\n", "\r\n", " ", "hello", "world", "this", "is", "text", "!", "benchmark", "for", "text" }; var rnd = new Random(0); while (sb.Length < length) { sb.Append(rnd.From(words)); } string oneMbString = sb.ToString(); CodeTimer timer = CodeTimer.Start(); string normalizedString = oneMbString.NormalizeLineEndings(); if (normalizedString.Length > 10) { TestContext.Out.WriteLine("String normalization speed = {0:F2} Mb/s", 1.0 / timer.Time); } }
public void StartTimerTest() { CodeTimer timer = new CodeTimer(typeof(CodeTimerTest), "StartTimerTest"); Assert.Equal(0, timer.ElapsedTime); Assert.Equal("start", timer.Start().SubeventName); Assert.Null(timer.Start()); Assert.True(timer.Started); Assert.True(timer.Running); long elapsed = timer.ElapsedTime; Thread.Sleep(1000); Assert.True(timer.ElapsedTime > 0); Assert.NotEqual(elapsed, timer.ElapsedTime); timer.Stop(); }
public void SpeedTest() { TestClass test = new TestClass(); test.Name = "Jason Zander"; test.Age = 30; test.Employeed = false; test.Time = new DateTime(2009, 1, 1); const int count = 1000; JsonSerializer.Serialize(test); JavaScriptSerializer serializer = new JavaScriptSerializer(); serializer.Serialize(test); CodeTimer timer = CodeTimer.Start(); for (int i = 0; i < count; i++) { string s = serializer.Serialize(test); } CodeTimer.WriteMilliseconds(timer); timer = CodeTimer.Start(); for (int i = 0; i < count; i++) { string s = JsonSerializer.Serialize(test); } CodeTimer.WriteMilliseconds(timer); }
public void TimerConstructorTest() { CodeTimer timer = new CodeTimer(typeof(CodeTimerTest), "TimerConstructorTest"); ICheckpoint[] checkpoints = new ICheckpoint[] { timer.Start(), timer.Stop() }; foreach (ICheckpoint checkpoint in checkpoints) { Assert.Equal(checkpoint.ClassName, typeof(CodeTimerTest).FullName); Assert.Equal(checkpoint.EventName, "TimerConstructorTest"); } }
public void StartedTest() { CodeTimer timer = new CodeTimer(typeof(CodeTimerTest), "StartedTest"); Assert.False(timer.Started); timer.Start(); Assert.True(timer.Started); timer.Stop(); Assert.True(timer.Started); timer = new CodeTimer(typeof(CodeTimerTest), "StartedTest2"); Assert.False(timer.Started); timer.Start(); Assert.True(timer.Started); timer.Fail(); Assert.True(timer.Started); }
public void RunningTest() { CodeTimer timer = new CodeTimer(typeof(CodeTimerTest), "RunningTest"); Assert.False(timer.Running); timer.Start(); Assert.True(timer.Running); timer.Stop(); Assert.False(timer.Running); timer = new CodeTimer(typeof(CodeTimerTest), "RunningTest2"); Assert.False(timer.Running); timer.Start(); Assert.True(timer.Running); timer.Fail(); Assert.False(timer.Running); }
public void PerformanceReads() { CodeTimer timer = CodeTimer.Start(); for (int i = 0; i < 100000; i++) { using (Id3TagEditor editor = new Id3TagEditor(Mp3Path, FileAccess.Read)) { Id3V11Tag tag = editor.Read(); Assert.AreEqual("Rob Towns", tag.Artist); Assert.AreEqual("Blind Willie's Big Album", tag.Album); Assert.AreEqual(1, tag.Track); Assert.AreEqual("Blind Willie", tag.Title); Assert.AreEqual(40, tag.Genre); } } CodeTimer.WriteMilliseconds(timer); }
public void SpeedTest() { List <TestClass> bigList = new List <TestClass>(); CryptoRandom random = new CryptoRandom("{A:10}"); for (int i = 0; i < 100000; i++) { bigList.Add(new TestClass(i, random.Generate(), DateTime.Now)); } CodeTimer timer = CodeTimer.Start(); MultiLevelComparer <TestClass> comparer = new MultiLevelComparer <TestClass>(); comparer.AddColumn("Id", SortDirection.Ascending); comparer.AddColumn("Name", SortDirection.Descending); bigList.Sort(comparer); Console.WriteLine("Sorted in {0} ms", CodeTimer.Stop(timer).TotalMilliseconds); }
public void OneDifferencePerformance() { ItemCollection expected = new ItemCollection(); ItemCollection actual = new ItemCollection(); const int count = 20000; for (int i = 0; i < count; i++) { expected.Add(new Item(i, "Scotty", i, DateTime.Now.Date)); actual.Add(new Item(i, "Bones", i, DateTime.Now.Date)); } CodeTimer timer = CodeTimer.Start(); DiffCollectionGenerator <Item> diffCollectionGenerator = new DiffCollectionGenerator <Item>("Day", "Id"); DiffCollection <Item> diffs = diffCollectionGenerator.GenerateDiffs(expected, actual); CodeTimer.WriteMilliseconds(timer); Assert.AreEqual(count, diffs.Count); }
public async Task AsyncInvokeTest() { CodeTimer timer = CodeTimer.Start(); int curThreadId = Thread.CurrentThread.ManagedThreadId; Task task = Task.Run( async() => { await DelayInSyncPart(curThreadId); }); timer.Time.Should().BeLessThan(0.5); await task; timer.Time.Should().BeGreaterThan(2.0); try { await Task.Run(ThrowTestException); } catch (InvalidOperationException) { // This is expected exception. } int my42 = await Task.Run(async() => await GiveMeTheAnswer()); my42.Should().Be(42); try { // ReSharper disable once UnusedVariable int hope42 = await Task.Run(GiveMeTheError); Assert.Fail(); } catch (InvalidOperationException) { // This is expected exception. } }
public void ThreadedSetup() { Timer = CodeTimer.Start(); }