0xDEADBEEF

RSS odkazy

test-php-unpack.php

30. 7. 2023 #kód
const ITERS = 30_000_000;
$str = $argv[0];

$s = hrtime(true);
$sink = 0;
for ($i = 0; $i < ITERS; $i++) {
  $sink += $i;
}
$e = hrtime(true);
printf("%-16s %5.2f\n", "empty loop", ($e - $s) / ITERS);

$s = hrtime(true);
$sink = 0;
for ($i = 0; $i < ITERS; $i++) {
  $sink += noop();
}
$e = hrtime(true);
printf("%-16s %5.2f\n", "noop loop", ($e - $s) / ITERS);


$s = hrtime(true);
for ($i = 0; $i < ITERS; $i++) {
  $sink += unpackInt32LE($str);
}
$e = hrtime(true);
printf("%-16s %5.2f\n", "unpackInt32LE", ($e - $s) / ITERS);

$s = hrtime(true);
for ($i = 0; $i < ITERS; $i++) {
  $sink += unpack('V', $str)[1];
}
$e = hrtime(true);
printf("%-16s %5.2f\n", "unpack", ($e - $s) / ITERS);
píše k47 (@kaja47, k47)