Exemple #1
0
	********************************************/
//nbVerbs
if (isset($_GET['nbVerbs'])) {
    $nbVerbs = htmlspecialchars($_GET['nbVerbs']);
    if ($nbVerbs > $MAX_VERBS_A_TIME) {
        $nbVerbs = $MAX_VERBS_A_TIME;
    } elseif ($nbVerbs < 1) {
        $nbVerbs = $DEFAULT_NBVERBS;
    }
    //To prevent my do...while loop to be infinite
    if ($nbVerbs > $nb) {
        echo 'Database length error<br />';
        exit;
    }
    //Getting randoms verbs
    $req = $db->query('SELECT * FROM verbs WHERE id IN ' . randoms($nbVerbs, $nb));
    //outputing the html form
    $content = '<form accept-charset="utf-8" method="post" action="?correction"><table>
			<tr><th>French</th><th>Infinitive</th><th>Preterit</th><th>Past Participle</th>';
    $i = 0;
    while ($data = $req->fetch()) {
        $content .= '<tr><td><input type="hidden" id="' . $i . '-french" name="' . $i . '-french" value="' . $data['french'] . '" />' . $data['french'] . '</td>
			<td><input type="text" id="' . $i . '-infinitive" name="' . $i . '-infinitive" /></td>
			<td><input type="text" id="' . $i . '-preterit" name="' . $i . '-preterit" /></td>
			<td><input type="text" id="' . $i . '-pastPart" name="' . $i . '-pastPart" /></td></tr>';
        $i++;
    }
    $content .= '</table>
		<input type="hidden" value="' . $nbVerbs . '" id="nbVerbs" name="nbVerbs" />
		<input type="submit" value="Submit !" /></form>';
    // Correction
// Do the math the new way and time it
$start = mtime();
$cc = cc($nums);
$time = mtime() - $start;
echo implode($nums[0]) . " - " . implode($nums[1]) . " = " . $cc . " (cc = " . $time . ")" . "<br>";

// ===================================================================================================
*/
// ===================================================================================================
// Uncomment this block if you want to test a lot.
$cycles = 1000;
$owtime = 0;
$cctime = 0;
echo number_format($cycles) . " cycles - random numbers between 1 and 1000.<br>";
for ($i = 0; $i < $cycles; $i++) {
    $nums = randoms();
    // Do the math the old way and time it
    $start = mtime();
    $ow = ow($nums);
    $end = mtime();
    $owtime += $end - $start;
    // Do the math the new way and time it
    $start = mtime();
    $cc = cc($nums);
    $end = mtime();
    $cctime += $end - $start;
}
echo "Total time for the old way : " . abs($owtime) . " seconds<br>";
echo "Total time for the new way : " . abs($cctime) . " seconds<br>";
// ===================================================================================================