Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class HomeController : Controller
- {
- const int IterationCount = 1000;
- private Stopwatch stopwatch = new Stopwatch();
- public ActionResult Index()
- {
- if(Session["mykey"] == null)
- Session["mykey"] = Guid.NewGuid();
- ViewBag.FirstWrite = TestWritePerformance();
- ViewBag.FirstReadAfterWrite = TestReadPerformance();
- TestWriteAverage();
- TestReadAverage();
- return View();
- }
- private void TestReadAverage()
- {
- long readSum = 0;
- for (int i = 0; i < IterationCount; i++)
- {
- readSum += TestReadPerformance();
- }
- ViewBag.AverageRead = readSum/IterationCount;
- }
- private void TestWriteAverage()
- {
- long writeSum = 0;
- for (int i = 0; i < IterationCount; i++)
- {
- writeSum += TestWritePerformance();
- }
- ViewBag.AverageWrite = writeSum/IterationCount;
- }
- private long TestReadPerformance()
- {
- stopwatch.Restart();
- var configFile = WebConfigurationManager.OpenWebConfiguration("~");
- var readAfterWrite = configFile.AppSettings.Settings["MYKEY"].Value;
- stopwatch.Stop();
- return stopwatch.ElapsedMilliseconds;
- }
- private long TestWritePerformance()
- {
- var guid = Guid.NewGuid().ToString();
- var configFile = WebConfigurationManager.OpenWebConfiguration("~");
- var settings = configFile.AppSettings.Settings;
- stopwatch.Restart();
- settings["MYKEY"].Value = guid;
- configFile.Save(ConfigurationSaveMode.Minimal);
- ConfigurationManager.RefreshSection("appSettings");
- stopwatch.Stop();
- return stopwatch.ElapsedMilliseconds;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement