-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperftest.php
More file actions
executable file
·55 lines (44 loc) · 1.44 KB
/
perftest.php
File metadata and controls
executable file
·55 lines (44 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env php
<?php
if (count($argv) < 2) {
echo "Syntax ${argv[0]} <directory> <number of files to create> <size in kb>\n";
exit;
}
$dir = $argv[1];
$num_files = $argv[2];
$file_size = $argv[3];
echo "Creating $num_files files {$file_size}KB each in $dir, total size " . number_format($file_size * $num_files) . "KB \n";
$buffer = str_repeat('x', 1024);
$start = $total_start = microtime(TRUE);
foreach (range(0, $num_files) as $number) {
// Create file, truncate if exists.
$file_path = gen_filepath($dir, $number);
$fh = fopen($file_path, 'w+');
if (!$fh) {
die("Could not create file $file_path\n");
}
for ($i = 0; $i < $file_size; $i++) {
fwrite($fh, $buffer);
}
}
$duration = round(microtime(TRUE) - $start, 2);
echo "Created $num_files files in $duration ms\n";
// Clear phps file stat cache.
clearstatcache();
$start = microtime(TRUE);
foreach (range(0, $num_files) as $number) {
stat(gen_filepath($dir, $number));
}
$duration = round(microtime(TRUE) - $start, 2);
echo "Got status of $num_files files in $duration ms \n";
$start = microtime(TRUE);
foreach (range(0, $num_files) as $number) {
file_get_contents(gen_filepath($dir, $number));
}
$duration = round(microtime(TRUE) - $start, 2);
echo "Read $num_files files in $duration ms \n";
$total_duration = round(microtime(TRUE) - $total_start, 2);
echo "** Total duration: $total_duration **\n";
function gen_filepath($dir, $number) {
return "$dir/file-$number";
}