adds a couple of benchmark tests if we need to refer to them in the future (they are ignored so won't run as part of the normal build)

This commit is contained in:
Shannon
2014-08-20 19:36:03 -06:00
parent 573c08295a
commit 067eceffce
3 changed files with 115 additions and 3 deletions

View File

@@ -41,7 +41,8 @@ namespace Umbraco.Core.Persistence.Caching
public static RuntimeCacheProvider Current { get { return lazy.Value; } }
private RuntimeCacheProvider()
//internal for testing! - though I'm not a huge fan of these being singletons!
internal RuntimeCacheProvider()
{
if (HttpContext.Current == null)
{
@@ -246,7 +247,7 @@ namespace Umbraco.Core.Persistence.Caching
private string GetCompositeId(Type type, Guid id)
{
return string.Format("{0}{1}-{2}", CacheItemPrefix, type.Name, id.ToString());
return string.Format("{0}{1}-{2}", CacheItemPrefix, type.Name, id);
}
private string GetCompositeId(Type type, int id)

View File

@@ -5,8 +5,10 @@ using System.Linq;
using System.Web;
using Moq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.EntityBase;
using Umbraco.Core.Persistence.Caching;
using Umbraco.Core.Serialization;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Entities;
@@ -14,7 +16,7 @@ using Umbraco.Tests.TestHelpers.Entities;
namespace Umbraco.Tests.Models
{
[TestFixture]
public class ContentTests
public class ContentTests : BaseUmbracoConfigurationTest
{
[SetUp]
public void Init()
@@ -181,6 +183,62 @@ namespace Umbraco.Tests.Models
Assert.AreNotSame(content.Properties, clone.Properties);
}
[Ignore]
[Test]
public void Can_Deep_Clone_Perf_Test()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
contentType.Id = 99;
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
var i = 200;
foreach (var property in content.Properties)
{
property.Id = ++i;
}
content.Id = 10;
content.CreateDate = DateTime.Now;
content.CreatorId = 22;
content.ExpireDate = DateTime.Now;
content.Key = Guid.NewGuid();
content.Language = "en";
content.Level = 3;
content.Path = "-1,4,10";
content.ReleaseDate = DateTime.Now;
content.ChangePublishedState(PublishedState.Published);
content.SortOrder = 5;
content.Template = new Template("-1,2,3,4", "Test Template", "testTemplate")
{
Id = 88
};
content.Trashed = false;
content.UpdateDate = DateTime.Now;
content.Version = Guid.NewGuid();
content.WriterId = 23;
((IUmbracoEntity)content).AdditionalData.Add("test1", 123);
((IUmbracoEntity)content).AdditionalData.Add("test2", "hello");
var runtimeCache = new RuntimeCacheProvider();
runtimeCache.Save(typeof(IContent), content);
using (DisposableTimer.DebugDuration<ContentTests>("STARTING PERF TEST WITH RUNTIME CACHE"))
{
for (int j = 0; j < 1000; j++)
{
var clone = runtimeCache.GetById(typeof(IContent), content.Id.ToGuid());
}
}
using (DisposableTimer.DebugDuration<ContentTests>("STARTING PERF TEST WITHOUT RUNTIME CACHE"))
{
for (int j = 0; j < 1000; j++)
{
var clone = (ContentType)contentType.DeepClone();
}
}
}
[Test]
public void Can_Deep_Clone()
{

View File

@@ -1,6 +1,7 @@
using System;
using System.Linq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.EntityBase;
using Umbraco.Core.Serialization;
@@ -90,6 +91,58 @@ namespace Umbraco.Tests.Models
}
}
[Ignore]
[Test]
public void Can_Deep_Clone_Content_Type_Perf_Test()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
contentType.Id = 99;
var i = 200;
foreach (var propertyType in contentType.PropertyTypes)
{
propertyType.Id = ++i;
}
foreach (var group in contentType.PropertyGroups)
{
group.Id = ++i;
}
contentType.AllowedTemplates = new[] { new Template("-1,2", "Name", "name") { Id = 200 }, new Template("-1,3", "Name2", "name2") { Id = 201 } };
contentType.AllowedContentTypes = new[] { new ContentTypeSort(new Lazy<int>(() => 888), 8, "sub"), new ContentTypeSort(new Lazy<int>(() => 889), 9, "sub2") };
contentType.Id = 10;
contentType.CreateDate = DateTime.Now;
contentType.CreatorId = 22;
contentType.SetDefaultTemplate(new Template("-1,2,3,4", "Test Template", "testTemplate")
{
Id = 88
});
contentType.Description = "test";
contentType.Icon = "icon";
contentType.IsContainer = true;
contentType.Thumbnail = "thumb";
contentType.Key = Guid.NewGuid();
contentType.Level = 3;
contentType.Path = "-1,4,10";
contentType.SortOrder = 5;
contentType.Trashed = false;
contentType.UpdateDate = DateTime.Now;
((IUmbracoEntity)contentType).AdditionalData.Add("test1", 123);
((IUmbracoEntity)contentType).AdditionalData.Add("test2", "hello");
using (DisposableTimer.DebugDuration<ContentTypeTests>("STARTING PERF TEST"))
{
for (int j = 0; j < 1000; j++)
{
using (DisposableTimer.DebugDuration<ContentTypeTests>("Cloning content type"))
{
var clone = (ContentType)contentType.DeepClone();
}
}
}
}
[Test]
public void Can_Deep_Clone_Content_Type()
{