internal static void Measure() { //Prepare the argument that will be passes to the template var class1 = new ClassDefinition { Name = "TestClass", Namespace = "TC.CustomTemplating.Example.Generated" }; class1.Properties.Add(new Property("Name", typeof(string))); class1.Properties.Add(new Property("Lenght", typeof(int))); class1.Properties.Add(new Property("L", typeof(int))); double min = double.MaxValue; double max = 0; double first = double.MinValue; const int numberOfTransformations = 100; //Get template from the embedded resources string template = TemplateResources.Get("TC.CustomTemplating.Example.Class.tt", typeof(ClassTemplate)); //Create a new domain wherein the transformation will //take place using (var transformer = new DomainTextTransformer()) { //We try to transform it n times Stopwatch watch = new Stopwatch(); for (int i = 0; i < numberOfTransformations; i++) { //start the tranformation watch.Reset(); watch.Start(); transformer.Transform(template, "Class", class1); watch.Stop(); //Measure var milliseconds = watch.ElapsedMilliseconds; if (first == double.MinValue) { first = milliseconds; } else { max = Math.Max(max, milliseconds); } min = Math.Min(min, milliseconds); } } Console.WriteLine("--BEGIN MEASUREMENT RESULTS--"); Console.WriteLine("Number Of Transformations: {0}", numberOfTransformations); Console.WriteLine("First Time: {0}ms", first); Console.WriteLine("Min Time: {0}ms", min); Console.WriteLine("Max Time: {0}ms (without first time)", max); Console.WriteLine("--END MEASUREMENT RESULTS--"); }
public void with_arguments_it_should_call_appDomainManager() { //Arrange _appDomain = AppDomain.CreateDomain(new Guid().ToString()); _appDomainManager.Setup(a => a.Create(It.IsAny <string>())).Returns(_appDomain); _engine.Setup(e => e.ProcessTemplate(Template, _host.Object)).Returns(Result); //Act _transformer = new DomainTextTransformer(_appDomainManager.Object, _host.Object, _engine.Object); _result = _transformer.Transform(Template); }
public void TestInitialize() { //Arrange _appDomain = AppDomain.CreateDomain(new Guid().ToString()); _appDomainManager.Setup(a => a.Create(It.IsAny <string>())).Returns(_appDomain); _engine.Setup(e => e.ProcessTemplate(Template, _host.Object)).Returns(Result); _transformer = new DomainTextTransformer(_appDomainManager.Object, _host.Object, _engine.Object); _initialAssemblies = _transformer.AssemblyReferences.Count; //Act _result = _transformer.Transform(Template, ArgumentName, null); }
public void with_arguments_it_should_call_appDomainManager() { //Arrange _appDomain = AppDomain.CreateDomain(new Guid().ToString()); _appDomainManager.Setup(a => a.Create(It.IsAny <string>())).Returns(_appDomain); _engine.Setup(e => e.ProcessTemplate(Template, _host.Object)).Returns(Result); _transformer = new DomainTextTransformer(_appDomainManager.Object, _host.Object, _engine.Object); _initialAssemblies = _transformer.AssemblyReferences.Count; _arguments = new TemplateArgumentCollection { new TemplateArgument(ArgumentName1, _argumentValue1), new TemplateArgument(ArgumentName2, _argumentValue2), }; //Act _result = _transformer.Transform(Template, _arguments); }