Using the benchmarking method described in my previous post, I set out to discover which is faster: C++ If statements or switch statements.

To do the test I had to ensure that the code was exactly the same besides the If and switch statement portions of the code. Below are my two like functions:

void IfStatement(){
    int val = 5;
    string value = "";
    for(int i = 0; i < 1000000; i++){
        if(val == 1) value = "one";
        else if(val == 2)…