Last active
August 29, 2015 14:23
-
-
Save cardinal252/1dbcc09e77b3ebeee84a to your computer and use it in GitHub Desktop.
Glass test code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Test] | |
[Timeout(120000)] | |
public void GetWholeDb() | |
{ | |
var rawItem = _db.GetItem("/sitecore"); | |
_service.Cast<StubForWholeDb>(rawItem); | |
Item[] items = rawItem.Axes.GetDescendants(); | |
_glassWatch.Reset(); | |
_rawWatch.Reset(); | |
var count = 0; | |
foreach (var item in items) | |
{ | |
_rawWatch.Start(); | |
// Glass performs a version count to ensure we have a version in the language | |
if (item.Versions.Count > 0) | |
{ | |
var value1 = rawItem["__DisplayName"]; | |
count++; | |
} | |
_rawWatch.Stop(); | |
_glassWatch.Start(); | |
var glassItem = _service.Cast<StubForWholeDb>(item); | |
if (glassItem != null) | |
{ | |
var value2 = glassItem.DisplayName; | |
} | |
_glassWatch.Stop(); | |
} | |
_rawTotal = _rawWatch.ElapsedTicks; | |
_glassTotal = _glassWatch.ElapsedTicks; | |
double total = _glassTotal / _rawTotal; | |
Console.WriteLine("Performance Test Count: {0} Ratio: {1} Average: {2}".Formatted(count, total, _glassTotal / count)); | |
Console.WriteLine("Total Items {0}", count); | |
} | |
public class StubForWholeDb | |
{ | |
[SitecoreId] | |
public virtual Guid Id { get; set; } | |
[SitecoreInfo(SitecoreInfoType.Name)] | |
public string Name { get; set; } | |
[SitecoreInfo(SitecoreInfoType.DisplayName)] | |
public string DisplayName { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment