通过控制台应用程序获取SharePoint网站页面加载时间的最佳方法是什么
本文关键字:时间 加载 最佳 是什么 方法 控制台 应用程序 获取 网站 SharePoint | 更新日期: 2023-09-27 18:30:02
我正在尝试创建一个控制台应用程序,用于计算sharePoint网站页面的页面加载时间。我需要缓存和未缓存的页面加载时间。
到目前为止,我已经尝试使用System.Net.WebClient和System.Diagnostic.ostopper来计算页面加载时间。但我仍然不确定做同样事情的最佳方法是什么。
使用WebClient的示例代码
class Program
{
static void Main(string[] args)
{
string urls = "https://www.google.com/";
using (WebClient client = new WebClient())
{
int i = 0;
for (i = 0; i < 2; i++)
{
//Get uncached data for the first time and next time get data from cache
if (i == 0)
client.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.BypassCache);
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();// start System.Diagnostics.Stopwatch before downloading url
client.Credentials = new System.Net.NetworkCredential("Username", "Password", "Domain");
String result = client.DownloadString(urls);
stopwatch.Stop();
Console.WriteLine(String.Format("{0} = {1}", urls, stopwatch.Elapsed.TotalSeconds));
}
}
}
}
取决于你真正想要的是什么。。。
如果你只是想偶尔对第一次和重复页面加载时间进行综合分析,webpagetest.org的私人实例可能会满足你的需求(设置起来很简单)
如果你想知道真正的用户体验是什么,请尝试boomerang.js或在谷歌分析中使用Site Speedd