forked from lukasmartinelli/php-dos-attack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.php
More file actions
executable file
·34 lines (31 loc) · 995 Bytes
/
Copy patharray.php
File metadata and controls
executable file
·34 lines (31 loc) · 995 Bytes
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
#!/usr/bin/php
<?php
$filename = $argv[1];
$file = file_get_contents($filename);
$lines = explode("\n", $file);
function measureEvilElements($elements) {
$startTime = microtime(true);
$array = array();
foreach($elements as $key) {
$array[$key] = 0;
}
$endTime = microtime(true);
return $endTime - $startTime;
}
function measureGoodElements($elements) {
$startTime = microtime(true);
$array = array();
for($key = 0; $key < count($elements); $key++) {
$array[strval($key)] = 0;
}
$endTime = microtime(true);
return $endTime - $startTime;
}
echo 'elements', 'evilTime', 'goodTime', "\r\n";
for($i = 0; $i < count($lines); $i+=500) {
$keys = array_slice($lines, 0, $i);
$evilTime = measureEvilElements($keys);
$goodTime = measureGoodElements($keys);
echo $i, ',', $evilTime, ',', $goodTime, "\r\n";
}
?>