title: C++ Function pointers vs Switch
body: <ul>
  <li>What is faster: Function pointers or switch?</li>
  </ul>
  
  <p>The switch statement would have around 30 <code>case</code>s, consisting of enumarated unsigned ints from 0 to 30.</p>
  
  <p>I could do the following:</p>
  
  <pre><code>class myType
  {
      FunctionEnum func;
      string argv[123];
      int someOtherValue;
  };
  // In another file:
  myType current;
  // Iterate through a vector containing lots of myTypes
   // ... for ( i=0; i &lt; myVecSize; i ++ )
      switch ( current.func )
      {
             case 1:
              //...
              break;
             // ........
             case 30:
               // blah
              break;
      }
  </code></pre>
  
  <p>And go trough the switch with <code>func</code> every time. The good thing about switch would also be that my code is more organized than with 30 functions.</p>
  
  <p>Or I could do that (not so sure with that):</p>
  
  <pre><code>class myType
  {
      myReturnType (*func)(int all, int of, int my, int args );
      string argv[123];
      int someOtherValue;
  };
  </code></pre>
  
  <p>I'd have 30 different functions then, at the beginning a pointer to one of them is assigned to myType.</p>
  
  <ul>
  <li>What is probably faster: Switch statement or function pointer?</li>
  </ul>
  
  <p>Calls per second: Around 10 million.
  I can't just test it out - that would require me to rewrite the whole thing. Currently using switch.</p>
  
  <p>I'm building an interpreter which I want to be faster than Python &amp; Ruby - every clock cycle matters!</p>