phpbench

Gesponsorde koppelingen

PHP script bestanden

  1. phpbench

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
<?php
/*
Dit is enkel de source, gebruik de downloads om te testen!
*/

?>


======bench_main.phpcli======
Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
//constants
require ('bench_conf.phpcli');

function
getmicrotime() {
   list($usec, $sec) = explode(" ",microtime());
   return ((float)$usec + (float)$sec);
}


$basestart = getmicrotime();

function
hugevar() {
  $nr = 0;
  while ($nr < (1024*1024)) { //1 meg var
    $hugevar .= rand(0, 9);
    $nr++;
  }

  return $hugevar;
}

function
leet($key) {  
  $known = array('o', 'e', '<', '>', 'w', 'a');
  $leet = array('0', '3', '*', '*', '&#092;&#092;\'', '4');
  if(rand(0, 1) == 1) {
    $key = strtoupper($key);
  }
else {
    $key = strtolower($key);
  }

  $key = str_replace($known, $leet, $key);
  return stripslashes($key);
}

function
leetsite ($url) { //original in http://www.phphulp.nl/php/scripts/7/303/
    $root = $_SERVER['DOCUMENT_ROOT'];
    $cont = file($url);
    if ($cont) {
      foreach($cont as $line) {
        $line = strtolower($line);
        $line = str_replace('src="/', 'src="', $line);
        $line = str_replace('href="/', 'href="', $line);
        $line = str_replace('background="/', 'background="', $line);
        $line = preg_replace('/src="(?!http:\/\/|ftp:\/\/)(.+?)"/', 'src="'.$root.'\\1"', $line);
        $line = preg_replace('/href="(?!http:\/\/|ftp:\/\/|mailto:)(.+?)"/', 'href="'.$root.'\\1"', $line);
        $line = preg_replace('/background="(?!http:\/\/)(.+?)"/', 'background="'.$root.'\\1"', $line);
        $bytes = preg_split('//', str_replace('&nbsp;', ' ', $line));
        foreach ($bytes as $byte) {
          if ($byte == '<') {
            $tagopen = 'yes';
          }

          if ($tagopen == 'yes' && $byte == '>') {
            $tagopen = 'no';
          }

          if ($tagopen == 'no' && $byte != '<' && $byte != '>') {
            $out =  leet($byte);
          }

          if ($byte == '<' || $byte == '>' || $tagopen == 'yes') {
            $out =  $byte;
          }
        }
      }
    }

    return $out;
  }

function
runrandtest($def_val, $def_range, $def_deci) {
  $start = getmicrotime();
  $ref2 = $def_range/2;
  $i = 0;
  $total = 0;
  while ($i < $def_val) {
    $val = rand(0, $def_range);
    $total += $val;
    $i++;
  }

  $ref = $total/$def_val;
  if ($ref > $ref2) {
    $dev = 100-$ref2/$ref*100;
  }
elseif ($ref < $ref2) {
    $dev = 100-$ref/$ref2*100;
  }
else {
    $dev = 0;
  }

  $micro = getmicrotime()-$start;
  return array('dev' => $dev, 'micro' => $micro);
}


echo "\r\n==PHP CLI Benchmark v0.1==\r\n";

$varbegin = getmicrotime();
echo "\r\nCreating variables";
$var1 = hugevar();
echo ".";
$var2 = hugevar();
echo ".";
$varend = getmicrotime();
$vartime = round($varend-$varbegin, $def_deci);

echo "\r\nRunning rand() deviation test";
$j = 0;
while($j < $def_numtests) {
  $funcout = runrandtest($def_val, $def_range, $def_deci);
  echo ".";
  $devs += $funcout['dev'];
  $micros += $funcout['micro'];
  $j++;
}


echo "\r\nRunning md5 sha1 hash creation test";
$k = 0;
while ($k < $def_numtests) {
  $countmd5 = 0;
  while ($countmd5 < $def_md5) {
    $md5start = getmicrotime();
    $newhash = md5($var1);
    $newhash2 = sha1($var2);
    unset($newhash, $newhash2);
    $countmd5++;
    $md5time += getmicrotime()-$md5start;
  }

  echo ".";
  $k++;
}


echo "\r\nRunning math test";
$l = 0;
while ($l < $def_numtests) {
  $countmath = 0;
  while ($countmath < $def_math) {
    $mathstart = getmicrotime();
    $math1 = bindec(decbin(hexdec(dechex(octdec(decoct($var1))))));
    $math2 = pow(sqrt($var2), $var1);
    unset($math1, $math2);
    $countmath++;
    $mathtime += getmicrotime()-$mathstart;
  }

  echo ".";
  $l++;
}


echo "\r\nRunning 1337-alizer (parsing) test";
$m = 0;
while ($m < $def_numtests) {
  $countleet = 0;
  while ($countleet < $def_leet) {
    $leetstart = getmicrotime();
    $leet = leetsite('bench_sitedump.html');
    unset($leet);
    $countleet++;
    $leettime += getmicrotime()-$leetstart;
  }

  echo ".";
  $m++;
}


$plusdev = round($devs/$def_numtests, $def_deci);
$plusmicro = round($micros/$def_numtests, $def_deci);
$plusmd5 = round($md5time/($def_numtests*$def_md5), $def_deci);
$plusmath = round($mathtime/($def_numtests*$def_math), $def_deci);
$plusleet = round($leettime/($def_numtests*$def_leet), $def_deci);

echo "\r\n\r\n";

echo "==while() variable creation test===============================\r\n";
echo "2 1meg variables created in: ".$vartime."s\r\n";
echo "==rand() deviation test========================================\r\n";
echo "Avg deviation: ".$plusdev.". Avg Comptime: ".$plusmicro."s\r\n";
echo "==while() md5 sha1 test========================================\r\n";
echo "Avg hash creation: ".$plusmd5."s\r\n";
echo "==math test====================================================\r\n";
echo "Avg calculation time: ".$plusmath."s\r\n";
echo "==1337-alizer (parsing) test===================================\r\n";
echo "Avg parsing time: ".$plusleet."s\r\n";
echo "\r\nDone in ".round(getmicrotime()-$basestart, $def_deci)."s.\r\n\r\n";
?>


======bench_conf.phpcli======
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
<?php
//PHP CLI benchmark config
$def_val = 1000000; //numer of rand()'s in one test
$def_range = 1000;  //the range for the rand() function
$def_deci = 10;     //decimals for the results
$def_numtests = 10; //number of tests on each test
$def_leet = 4;      //Number of 1337-alizer runs each test
$def_math = 70;     //Number of math runs each test
$def_md5 = 100;     //Number of hash runs each test
?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.