title: Why is lock much slower than Monitor.TryEnter?
body: <p>Results</p>
  
  <p>Lock: 85.3 microseconds</p>
  
  <p>Monitor.TryEnter: 11.0 microseconds</p>
  
  <p>Isn't the lock expanded into the same code?</p>
  
  <p>Edit: Results with 1000 iterations:
  Lock: 103.3 microseconds
  Monitor.TryEnter: 20.2 microseconds</p>
  
  <p>Code below. Thanks</p>
  
  <pre><code>    [Test]
      public void Lock_Performance_Test()
      {
          const int lockIterations = 100;
  
          Stopwatch csLock = Stopwatch.StartNew();
          for (int i = 0; i &lt; lockIterations; )
          {
              lock (object1)
              {
                  i++;
              }
          }
          csLock.Stop();
  
          Stopwatch csMonitor = Stopwatch.StartNew();
          for (int i = 0; i &lt; lockIterations; )
          {
              if (Monitor.TryEnter(object1, TimeSpan.FromSeconds(10)))
              {
                  try
                  {
                      i++;
                  }
                  finally
                  {
                      Monitor.Exit(object1);
                  }
              }
          }
          csMonitor.Stop();
  
          Console.WriteLine("Lock: {0:f1} microseconds", csLock.Elapsed.Ticks / 10M);
          Console.WriteLine("Monitor.TryEnter: {0:f1} microseconds", csMonitor.Elapsed.Ticks / 10M);;
      }
  </code></pre>