title: Performance - FunctionCall vs Event vs Action vs Delegate
body: <p>Currently I am using Microsoft Sync Framework to synchronize databases. I need to gather information per record which is inserted/updated/deleted by Microsoft Sync Framework and do something with this information. </p>
  
  <p>The sync speed can go over 50.000 records per minute. So that means my additional code need to be very lightweight otherwise it will be a huge performance penalty. </p>
  
  <p>Microsoft Sync Framework raises an <code>SyncProgress</code> event for each record. I am subscribed to that code like this:</p>
  
  <pre><code>// Assembly1
  SyncProvider.SyncProgress += OnSyncProgress;
  // ....
  private void OnSyncProgress(object sender, DbSyncProgressEventArgs e)
  {
      switch (args.Stage)
      {
          case DbSyncStage.ApplyingInserts:
              // MethodCall/Delegate/Action&lt;&gt;/EventHandler&lt;&gt; =&gt; HandleInsertedRecordInformation 
              // Do something with inserted record info
              break;
          case DbSyncStage.ApplyingUpdates:
              // MethodCall/Delegate/Action&lt;&gt;/EventHandler&lt;&gt; =&gt; HandleUpdatedRecordInformation  
              // Do something with updated record info
              break;
          case DbSyncStage.ApplyingDeletes:
              // MethodCall/Delegate/Action&lt;&gt;/EventHandler&lt;&gt; =&gt; HandleDeletedRecordInformation
              // Do something with deleted record info
              break;
      }
  }
  </code></pre>
  
  <p>Somewhere else in another assembly I have three methods:</p>
  
  <pre><code>// Assembly2
  public class SyncInformation
  {
      public void HandleInsertedRecordInformation(...) {...}
      public void HandleUpdatedRecordInformation(...) {...}
      public void HandleInsertedRecordInformation(...) {...}
  }
  </code></pre>
  
  <p><code>Assembly2</code> has a reference to <code>Assembly1</code>. So <code>Assembly1</code> does not know anything about the existence of the <code>SyncInformation</code> class which need to handle the gathered information. So I have the following options to trigger this code:</p>
  
  <ol>
  <li>use events and subscribe on it in <code>Assembly2</code><br>
  1.1. EventHandler&lt;><br>
  1.2. Action&lt;><br>
  1.3. Delegates  </li>
  <li>using dependency injection:<br>
  <code>public class Assembly2.SyncInformation : Assembly1.ISyncInformation</code></li>
  <li>Other?</li>
  </ol>
  
  <p>I know the performance depends on:</p>
  
  <ul>
  <li>OnSyncProgress
  <ul>
  <li>switch</li>
  <li>using a method call, delegate, Action&lt;> or EventHandler&lt;></li>
  </ul></li>
  <li>Implementation of SyncInformation class</li>
  </ul>
  
  <p>I currently don't care about the implementation of the <code>SyncInformation</code> class. I am mainly focused on the <code>OnSyncProgress</code> method and how to call the <code>SyncInformation</code> methods. </p>
  
  <p>So my questions are:</p>
  
  <ul>
  <li><strong>What is the most efficient approach?</strong></li>
  <li><strong>What is the most in-efficient approach?</strong></li>
  <li><strong>Is there a better way than using a switch in <code>OnSyncProgress</code>?</strong> </li>
  </ul>