title: File Write Duration on Azure VM with Windows Server 2012
body: <p>I recently had to log the time it takes to write a file for some reason. I did this on Windows Server 2012 on an Azure VM. When I looked at the logs, most of the times were 0 ms, only very few were 15.something ms. I thought I did something wrong with the measurement and tested with this piece of code:</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          string dir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\TEST";
          if (!Directory.Exists(dir))
          {
              Directory.CreateDirectory(dir);
          }
  
          for (int i = 0; i &lt; 10; i++)
          {
              DateTime start = DateTime.Now;
              File.WriteAllText(dir + @"\test.txt", "test");
              DateTime end = DateTime.Now;
              TimeSpan duration = end - start;
              double ms = duration.TotalMilliseconds;
              File.AppendAllText(dir+@"\log.txt", Convert.ToString(ms) + System.Environment.NewLine);
          }
      }
  }
  </code></pre>
  
  <p>Output on my PC (OS locale set to German, so the comma is a decimal mark, not a thousands separator, making the first number 5 ms):</p>
  
  <pre><code>5,0037 1,001 0,9976 1,001 1,001 2,002 0,9956 2,002 1,0003 0,9996
  </code></pre>
  
  <p>Output on the remote machine:</p>
  
  <pre><code>0 0 0 0 0 0 0 0 0 0
  </code></pre>
  
  <p>And sometimes (OS locale set to English, so the point is the decimal mark, making the relevant number 15.5 ms):</p>
  
  <pre><code>0 0 0 0 0 0 15.4914 0 0 0
  </code></pre>
  
  <p>What's the reason for that? Is this some write-cache either on Windows Server 2012 or Azure VM?</p>
  
  <p>Additional info:</p>
  
  <ul>
  <li>My PC has a single SSD, the remote machine is configured with the OS and Data on seperate drives (not sure what type)</li>
  </ul>