From 5879d3ac3162c05221bb855edf40bcedae99fdef Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 29 May 2011 23:47:11 -0700 Subject: [PATCH] Added dbBenchmark tests --- NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 1 + NzbDrone.Core.Test/dbBenchmark.cs | 119 +++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 NzbDrone.Core.Test/dbBenchmark.cs diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 068d76fb8..164ca5c6b 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -85,6 +85,7 @@ + diff --git a/NzbDrone.Core.Test/dbBenchmark.cs b/NzbDrone.Core.Test/dbBenchmark.cs new file mode 100644 index 000000000..4510f78de --- /dev/null +++ b/NzbDrone.Core.Test/dbBenchmark.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading; +using FizzWare.NBuilder; +using Gallio.Framework; +using MbUnit.Framework; +using MbUnit.Framework.ContractVerifiers; +using NzbDrone.Core.Repository; +using NzbDrone.Core.Test.Framework; + +namespace NzbDrone.Core.Test +{ + [TestFixture] + // ReSharper disable InconsistentNaming + public class DbBenchmark + { + const int COUNT = 10000; + private List episodes; + private List files; + + + [SetUp] + public void Setup() + { + + + episodes = new List(COUNT); + files = new List(COUNT); + + for (int i = 10; i < COUNT + 10; i++) + { + var file = Builder.CreateNew().With(c => c.EpisodeFileId = i).Build(); + files.Add(file); + + var episode = Builder.CreateNew() + .With(c => c.EpisodeId = i) + .And(c => c.EpisodeFileId = i) + .And(c => c.Title = DateTime.Now.ToLongTimeString()) + .And( + c => + c.Overview = + @"This adds support for silverlight. Both the 3.5 CLR and a Silverlight 3 + version are included in the zip file. Also includes some other very minor bug fixes.").Build(); + + episodes.Add(episode); + } + } + + + + [Test] + public void Insert_into_episodes() + { + var repo = MockLib.GetEmptyRepository(); + + Thread.Sleep(1000); + var sw = Stopwatch.StartNew(); + repo.AddMany(episodes); + sw.Stop(); + + Console.WriteLine("Adding " + COUNT + " items at once took " + sw.Elapsed); + } + + + [Test] + public void Insert_into_episodes_single() + { + var repo = MockLib.GetEmptyRepository(); + + Thread.Sleep(1000); + var sw = Stopwatch.StartNew(); + + for (int i = 0; i < 100; i++) + { + repo.Add(episodes[i]); + } + + sw.Stop(); + + Console.WriteLine("Adding " + 100 + " single items took " + sw.Elapsed); + } + + + [Test] + public void get_episode_file() + { + var repo = MockLib.GetEmptyRepository(); + + repo.AddMany(episodes); + repo.AddMany(files); + + //var repoEpisodes = repo.All().ToList(); + + Thread.Sleep(1000); + + var count = 0; + + var random = new Random(); + + var sw = Stopwatch.StartNew(); + + + + for (int i = 5000; i < 5000 + 1000; i++) + { + count++; + var file = repo.Single(random.Next(0, COUNT)).EpisodeFile; + } + + + sw.Stop(); + + Console.WriteLine("Getting " + count + " episode files took " + sw.Elapsed); + } + } +}