Is ‘switch’ faster than ‘if’?

Is a switch statement actually faster than an if statement? I ran the code below on Visual Studio 2010’s x64 C++ compiler with the /Ox flag: #include <stdlib.h> #include <stdio.h> #include <time.h> #define MAX_COUNT (1 << 29) size_t counter = 0; size_t testSwitch() { clock_t start = clock(); size_t i; for (i = 0; i … Read more