Exemplo n.º 1
0
            $i++;
            break;
        case 8:
            $i++;
            break;
        case 9:
            $i++;
            break;
        default:
            $i++;
    }
}
function benchmark_compare_two()
{
    $n = rand(0, 9);
    $i = 0;
    $n == 0 ? $i++ : $n == 1 ? $i++ : $n == 2 ? $i++ : $n == 3 ? $i++ : $n == 4 ? $i++ : $n == 5 ? $i++ : $n == 6 ? $i++ : $n == 7 ? $i++ : $n == 8 ? $i++ : $n == 9 ? $i++ : $i++;
}
// Add them
$benchmark->addFunction('switch(){}', 'benchmark_compare_one');
$benchmark->addFunction('?: operator', 'benchmark_compare_two');
// Benchmark by time
echo "Benchmark by time...\n";
$time = $benchmark->benchmarkTime(2);
// two functions * 2 seconds = 4 seconds
$time->outputTable();
// Benchmark by calls
echo "Benchmark by calls...\n";
$count = $benchmark->benchmarkCount(1000000);
// two functions * 100000 calls = 200000 calls
$count->outputTable();