Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Output:
- normale: 0.54769611358643 s
- veloce: 0.0072240829467773 s
- Codice:
- <?php
- function normale() {
- $square_vals = array();
- for ($i = 0; $i < 23; $i++) {
- $square_vals[$i] = range($i, $i + 3);
- }
- $t0 = microtime(true);
- for ($i = 0; $i < 100000; $i++) {
- $n = $i % 36;
- $ret = array();
- foreach ($square_vals as $value) {
- if (in_array($n, $value)) {
- array_push($ret, $i);
- }
- }
- }
- $delta = microtime(true) - $t0;
- echo "normale: $delta s";
- }
- function veloce() {
- $square_vals = array();
- for ($i = 0; $i < 37; $i++) {
- $square_vals[$i] = range($i, $i + 2);
- }
- $t0 = microtime(true);
- for ($i = 0; $i < 100000; $i++) {
- $n = $i % 36;
- $ret = $square_vals[$n];
- }
- $delta = microtime(true) - $t0;
- echo "veloce: $delta s";
- }
- normale();
- echo "<br>";
- veloce();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement