Last active
March 13, 2017 15:12
-
-
Save lowedown/2771200b2d71d4e54bbd97fc25a915f7 to your computer and use it in GitHub Desktop.
Sitecore database speed test
This file contains hidden or 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
| <%@ Page Language="C#" AutoEventWireup="true" %> | |
| <%@ Import Namespace="System.Data.SqlClient" %> | |
| <%@ Import Namespace="System.Diagnostics" %> | |
| <%@ Import Namespace="Sitecore.Data" %> | |
| <!DOCTYPE html> | |
| <html xmlns="http://www.w3.org/1999/xhtml"> | |
| <head runat="server"> | |
| <title></title> | |
| </head> | |
| <body> | |
| <form id="form1" runat="server"> | |
| <div> | |
| <h1>Test Sitecore database response time</h1> | |
| <p>This test fetches the specified item multiple times bypassing database cache.</p> | |
| <label>Database:</label><br/> | |
| <asp:TextBox runat="server" ID="Database" Text="web"/><br/> | |
| <label>Item to fetch:</label><br/> | |
| <asp:TextBox runat="server" ID="ItemToFetch" Text="/sitecore/content"/><br/> | |
| <label>Number of executions:</label><br/> | |
| <asp:TextBox runat="server" ID="NumberOfExecutions" Text="10000"/><br/> | |
| <br/> | |
| <asp:Button runat="server" OnClick="RunTest" Text="Run" /> | |
| <asp:Button runat="server" OnClick="RunSqlOnlyTest" Text="Run SQL only" /> | |
| <asp:Literal runat="server" ID="Result"/> | |
| </div> | |
| <script runat="server"> | |
| protected void RunTest(object sender, EventArgs e) | |
| { | |
| var sw = new Stopwatch(); | |
| using (new DatabaseCacheDisabler()) | |
| { | |
| sw.Start(); | |
| for (int i = 0; i < int.Parse(NumberOfExecutions.Text); i++) | |
| { | |
| var test = Sitecore.Data.Database.GetDatabase(Database.Text).GetItem(ItemToFetch.Text).Name; | |
| } | |
| sw.Stop(); | |
| } | |
| Result.Text = sw.ElapsedMilliseconds + "ms"; | |
| } | |
| protected void RunSqlOnlyTest(object sender, EventArgs e) | |
| { | |
| var sw = new Stopwatch(); | |
| sw.Start(); | |
| using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings[Database.Text].ConnectionString)) | |
| { | |
| var command = new SqlCommand("select 1", connection); | |
| connection.Open(); | |
| for (int i = 0; i < int.Parse(NumberOfExecutions.Text); i++) | |
| { | |
| command.ExecuteScalar(); | |
| } | |
| } | |
| sw.Stop(); | |
| Result.Text = "SQL only: " + sw.ElapsedMilliseconds + "ms"; | |
| } | |
| </script> | |
| </form> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment