diff --git a/src/React.sln b/src/React.sln index 667493019..c7771aa62 100644 --- a/src/React.sln +++ b/src/React.sln @@ -70,7 +70,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "React.Sample.CoreMvc", "Rea EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "React.Router.Mvc4", "React.Router.Mvc4\React.Router.Mvc4.csproj", "{2170D912-86E9-4CE3-8DA4-E1DE8D958E63}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "React.Sample.Router.CoreMvc", "React.Sample.Router.CoreMvc\React.Sample.Router.CoreMvc.csproj", "{5BFA69C8-2E66-4112-AC30-CE31503F4175}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "React.Sample.Router.CoreMvc", "React.Sample.Router.CoreMvc\React.Sample.Router.CoreMvc.csproj", "{5BFA69C8-2E66-4112-AC30-CE31503F4175}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "React.Tests.Benchmarks", "..\tests\React.Tests.Benchmarks\React.Tests.Benchmarks.csproj", "{083462CB-2FC0-4508-A7ED-4B77B44C3E23}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -154,6 +156,10 @@ Global {5BFA69C8-2E66-4112-AC30-CE31503F4175}.Debug|Any CPU.Build.0 = Debug|Any CPU {5BFA69C8-2E66-4112-AC30-CE31503F4175}.Release|Any CPU.ActiveCfg = Release|Any CPU {5BFA69C8-2E66-4112-AC30-CE31503F4175}.Release|Any CPU.Build.0 = Release|Any CPU + {083462CB-2FC0-4508-A7ED-4B77B44C3E23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {083462CB-2FC0-4508-A7ED-4B77B44C3E23}.Debug|Any CPU.Build.0 = Debug|Any CPU + {083462CB-2FC0-4508-A7ED-4B77B44C3E23}.Release|Any CPU.ActiveCfg = Release|Any CPU + {083462CB-2FC0-4508-A7ED-4B77B44C3E23}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -178,6 +184,7 @@ Global {305918EF-AD05-4743-9B3A-DB1CE84D467E} = {A51CE5B6-294F-4D39-B32B-BF08DAF9B40B} {2170D912-86E9-4CE3-8DA4-E1DE8D958E63} = {681C45FB-103C-48BC-B992-20C5B6B78F92} {5BFA69C8-2E66-4112-AC30-CE31503F4175} = {A51CE5B6-294F-4D39-B32B-BF08DAF9B40B} + {083462CB-2FC0-4508-A7ED-4B77B44C3E23} = {F567B25C-E869-4C93-9C96-077761250F87} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {DCF4A41E-C60D-4086-98A9-6F8508D7E8D0} diff --git a/tests/React.Tests.Benchmarks/Program.cs b/tests/React.Tests.Benchmarks/Program.cs new file mode 100644 index 000000000..61eba1eb3 --- /dev/null +++ b/tests/React.Tests.Benchmarks/Program.cs @@ -0,0 +1,69 @@ +using System; +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Running; +using JavaScriptEngineSwitcher.ChakraCore; +using JavaScriptEngineSwitcher.Core; +using Newtonsoft.Json.Linq; +using React.Web.Mvc; + +namespace React.Tests.Benchmarks +{ + public static class Program + { + public static void Main(string[] args) + { + var summary = BenchmarkRunner.Run(); + } + + [MemoryDiagnoser] + public class ComponentRenderBenchmarks + { + public static void PopulateTestData() + { + for (int i = 0; i < 10000; i++) + { + _testData.Add("key" + i, "value" + i); + } + } + + public ComponentRenderBenchmarks() + { + PopulateTestData(); + + Initializer.Initialize(registration => registration.AsSingleton()); + AssemblyRegistration.Container.Register(); + AssemblyRegistration.Container.Register(); + JsEngineSwitcher.Instance.EngineFactories.Add(new ChakraCoreJsEngineFactory()); + JsEngineSwitcher.Instance.DefaultEngineName = ChakraCoreJsEngine.EngineName; + + ReactSiteConfiguration.Configuration + .SetReuseJavaScriptEngines(false) + .AddScript("Sample.jsx"); + } + + [Benchmark] + public void HtmlHelperExtensions_React() + { + AssertContains("Hello Tester!", HtmlHelperExtensions.React(null, "HelloWorld", _testData, serverOnly: true).ToHtmlString()); + } + + [Benchmark] + public void Environment_CreateComponent() + { + var component = ReactEnvironment.Current.CreateComponent("HelloWorld", _testData, serverOnly: true); + AssertContains("Hello Tester!", component.RenderHtml(renderServerOnly: true)); + ReactEnvironment.Current.ReturnEngineToPool(); + } + + private static JObject _testData = JObject.FromObject(new System.Collections.Generic.Dictionary(){ ["name"] = "Tester" }); + } + + private static void AssertContains(string expected, string actual) + { + if (!actual.Contains(expected)) + { + throw new InvalidOperationException($"Strings were not equal. {expected} {actual}"); + } + } + } +} diff --git a/tests/React.Tests.Benchmarks/React.Tests.Benchmarks.csproj b/tests/React.Tests.Benchmarks/React.Tests.Benchmarks.csproj new file mode 100644 index 000000000..32211555e --- /dev/null +++ b/tests/React.Tests.Benchmarks/React.Tests.Benchmarks.csproj @@ -0,0 +1,29 @@ + + + + Exe + net461 + + + + + + + + + + + + + + + + + + + + Always + + + + diff --git a/tests/React.Tests.Benchmarks/Sample.jsx b/tests/React.Tests.Benchmarks/Sample.jsx new file mode 100644 index 000000000..582acfc97 --- /dev/null +++ b/tests/React.Tests.Benchmarks/Sample.jsx @@ -0,0 +1,10 @@ +class HelloWorld extends React.Component { + render() { + return ( +
+ Hello {this.props.name}! + All props: {JSON.stringify(this.props)} +
+ ); + } +}