Skip to content

Instantly share code, notes, and snippets.

@g105b
Created February 4, 2019 15:36
Show Gist options
  • Save g105b/2ad980429a34e7965e4f1529829af9d8 to your computer and use it in GitHub Desktop.
Save g105b/2ad980429a34e7965e4f1529829af9d8 to your computer and use it in GitHub Desktop.
<?php
$startTime = microtime(true);
$workingDir = "_bm";
$runs = [
100,
1000,
10000,
100000,
];
mkdir($workingDir);
chdir($workingDir);
$value = 0;
foreach($runs as $runIndex => $n) {
echo "Running test $runIndex ($n)..." . PHP_EOL;
for($i = 0; $i < $n; $i++) {
file_put_contents(implode("-", [$n, $i]), $i);
}
echo "Created, checking..." . PHP_EOL;
$files = glob("*");
$found = 0;
foreach($files as $f) {
if(file_exists($f)) {
$found ++;
unlink($f);
}
}
echo "Found $found files, should be " . count($files) . "." . PHP_EOL;
$now = microtime(true);
$duration = $now - $startTime;
echo "Time: $duration" . PHP_EOL;
}
chdir("..");
rmdir($workingDir);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment