Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <pre>
- <?php
- error_reporting(-1);
- //============================
- define('_INPUT','Hello Word');
- //============================
- $p=0;
- $dt[$p]['n']='Cahya DSN #1';
- echo "===Cahya DSN #1\n";
- $t1 = microtime(true);
- $m1=memory_get_usage();
- $input=_INPUT;
- $l=strlen($input);
- $input.=strrev($input);
- for($i=0;$i<$l;$i++) echo substr($input,$l-$i-1,($i+1)*2),"\n";
- $m2=memory_get_usage();
- $t2 = microtime(true);
- $dt[$p]['t']=$t2-$t1;
- $dt[$p]['m']=$m2-$m1;
- echo "Makan waktu: ".($t2 - $t1)." microsecond\n";
- echo "Makan memory: ".($m2 - $m1)." bytes\n";
- unset($input);
- unset($m1);
- unset($m2);
- unset($l);
- unset($i);
- //============================
- $p=1;
- $dt[$p]['n']='Cahya DSN #2';
- echo "===Cahya DSN #2\n";
- $t1 = microtime(true);
- $m1=memory_get_usage();
- $input=_INPUT;
- $l=strlen($input);
- $input.=strrev($input);
- for($i=0;$i<$l;$i++) echo str_pad(substr($input,$l-$i-1,($i+1)*2),$l*2,' ',STR_PAD_BOTH),"\n";
- $m2=memory_get_usage();
- $t2 = microtime(true);
- $dt[$p]['t']=$t2-$t1;
- $dt[$p]['m']=$m2-$m1;
- echo "Makan waktu: ".($t2 - $t1)." microsecond\n";
- echo "Makan memory: ".($m2 - $m1)." bytes\n";
- unset($input);
- unset($m1);
- unset($m2);
- unset($l);
- unset($i);
- //=============================
- $p=3;
- $dt[$p]['n']='Sandy Racy';
- echo "\n===Sandy Racy \n";
- $t1 = microtime(true);
- $m1=memory_get_usage();
- $input=_INPUT;
- $n=strlen($input);
- for($h=$n;$h>=0;$h--)
- {
- for($i=$h;$i<$n;$i++){
- $hasil.=$input[$i];
- }
- for($j=$n;$j>=$h;$j--){
- $hasil.=$input[$j];
- }
- $hasil.="\n";
- }
- echo $hasil;
- $m2=memory_get_usage();
- $t2 = microtime(true);
- $dt[$p]['t']=$t2-$t1;
- $dt[$p]['m']=$m2-$m1;
- echo "Makan waktu: ".($t2 - $t1)." microsecond\n";
- echo "Makan memory: ".($m2 - $m1)." bytes\n";
- unset($input);
- unset($m1);
- unset($m2);
- unset($h);
- unset($n);
- unset($i);
- unset($j);
- unset($hasil);
- //=============================
- $p=4;
- $dt[$p]['n']='Sandy racy *';
- echo "\n===Sandy Racy *\n";
- $t1 = microtime(true);
- $m1=memory_get_usage();
- $input=_INPUT;
- $n=strlen($input);
- $hasil='';
- for($h=$n-1;$h>=0;$h--)
- {
- for($i=$h;$i<$n;$i++){
- $hasil.=$input[$i];
- }
- for($j=$n-1;$j>=$h;$j--){
- $hasil.=$input[$j];
- }
- $hasil.="\n";
- }
- echo $hasil;
- $m2=memory_get_usage();
- $t2 = microtime(true);
- $dt[$p]['t']=$t2-$t1;
- $dt[$p]['m']=$m2-$m1;
- echo "Makan waktu: ".($t2 - $t1)." microsecond\n";
- echo "Makan memory: ".($m2 - $m1)." bytes\n";
- unset($input);
- unset($m1);
- unset($m2);
- unset($h);
- unset($n);
- unset($i);
- unset($j);
- unset($hasil);
- //============================
- $p=5;
- $dt[$p]['n']='Nusantara Prasetya Wijaya';
- echo "\n===Nusantara Prasetya Wijaya\n";
- $t1 = microtime(true);
- $m1=memory_get_usage();
- $input=_INPUT;
- $length=strlen($input);
- for($i=1;$i<$length;$i++)
- {
- for($f=$length-$i;$f<=$length;$f++) echo $input[$f];
- for($b=$length;$b>=$length-$i;$b--) echo $input[$b];
- }
- $m2=memory_get_usage();
- $t2 = microtime(true);
- $dt[$p]['t']=$t2-$t1;
- $dt[$p]['m']=$m2-$m1;
- echo "Makan waktu: ".($t2 - $t1)." microsecond\n";
- echo "Makan memory: ".($m2 - $m1)." bytes\n";
- unset($input);
- unset($m1);
- unset($m2);
- unset($length);
- unset($i);
- unset($f);
- unset($b);
- //============================
- $p=6;
- $dt[$p]['n']='Nusantara Prasetya Wijaya *';
- echo "\n===Nusantara Prasetya Wijaya *\n";
- $t1 = microtime(true);
- $m1=memory_get_usage();
- $input=_INPUT;
- $length=strlen($input);
- for($i=0;$i<$length;$i++)
- {
- for($f=$length-$i;$f<=$length;$f++) echo $input[$f-1];
- for($b=$length-1;$b>=$length-$i-1;$b--) echo $input[$b];
- echo "\n";
- }
- $m2=memory_get_usage();
- $t2 = microtime(true);
- $dt[$p]['t']=$t2-$t1;
- $dt[$p]['m']=$m2-$m1;
- echo "Makan waktu: ".($t2 - $t1)." microsecond\n";
- echo "Makan memory: ".($m2 - $m1)." bytes\n";
- unset($input);
- unset($m1);
- unset($m2);
- unset($length);
- unset($i);
- unset($f);
- unset($b);
- //============================
- $p=7;
- $dt[$p]['n']='C Rieqy IfIndefXor PetangatusteluForbidden';
- echo "\n=== C Rieqy IfIndefXor PetangatusteluForbidden\n";
- $t1 = microtime(true);
- $m1=memory_get_usage();
- $input=_INPUT;
- $len=strlen($input);
- $a=$len;
- for($c=$len;$c>=0;$c--){
- for($d=$c;$d<$len;$d++){
- echo $input[$d];
- }
- for($b=$len;$b>$a;$b--){
- echo $input[$b-1];
- }
- echo "\n";
- $a++;
- }
- $m2=memory_get_usage();
- $t2 = microtime(true);
- $dt[$p]['t']=$t2-$t1;
- $dt[$p]['m']=$m2-$m1;
- echo "Makan waktu: ".($t2 - $t1)." microsecond\n";
- echo "Makan memory: ".($m2 - $m1)." bytes\n";
- unset($input);
- unset($m1);
- unset($m2);
- unset($len);
- unset($c);
- unset($d);
- unset($b);
- unset($a);
- //============================
- $p=8;
- $dt[$p]['n']='C Rieqy IfIndefXor PetangatusteluForbidden *';
- echo "\n=== C Rieqy IfIndefXor PetangatusteluForbidden *\n";
- $t1 = microtime(true);
- $m1=memory_get_usage();
- $input=_INPUT;
- $len=strlen($input);
- $a=$len;
- for($c=$len;$c>=0;$c--){
- for($d=$c;$d<$len;$d++){
- echo $input[$d];
- }
- for($b=$len;$b>$a;$b--){
- echo $input[$b-1];
- }
- echo "\n";
- $a--;
- }
- $m2=memory_get_usage();
- $t2 = microtime(true);
- $dt[$p]['t']=$t2-$t1;
- $dt[$p]['m']=$m2-$m1;
- echo "Makan waktu: ".($t2 - $t1)." microsecond\n";
- echo "Makan memory: ".($m2 - $m1)." bytes\n";
- unset($input);
- unset($m1);
- unset($m2);
- unset($len);
- unset($c);
- unset($d);
- unset($b);
- unset($a);
- //============================
- $p=9;
- $dt[$p]['n']='Alfian Syahputra';
- echo "\n===Alfian Syahputra\n";
- $t1 = microtime(true);
- $m1=memory_get_usage();
- $a=_INPUT;
- for($i=strlen($a);$i>=0;$i--){
- $b=substr($a,$i);
- echo $b.strrev($b)."\n";
- }
- $m2=memory_get_usage();
- $t2 = microtime(true);
- $dt[$p]['t']=$t2-$t1;
- $dt[$p]['m']=$m2-$m1;
- echo "Makan waktu: ".($t2 - $t1)." microsecond\n";
- echo "Makan memory: ".($m2 - $m1)." bytes\n";
- unset($a);
- unset($m1);
- unset($m2);
- unset($i);
- unset($b);
- unset($hasil);
- //============================
- $p=10;
- $dt[$p]['n']='Ruli Armando';
- echo "\n===Ruli Armando\n";
- $t1 = microtime(true);
- $m1=memory_get_usage();
- $input=_INPUT;for($s=strrev($input),$i=0,$o='';$c=@$s[$i++];) echo$o="$c$o$c","\n";
- $m2=memory_get_usage();
- $t2 = microtime(true);
- $dt[$p]['t']=$t2-$t1;
- $dt[$p]['m']=$m2-$m1;
- echo "Makan waktu: ".($t2 - $t1)." microsecond\n";
- echo "Makan memory: ".($m2 - $m1)." bytes\n";
- unset($input);
- unset($m1);
- unset($m2);
- unset($i);
- unset($b);
- unset($hasil);
- //============================
- $p=11;
- $dt[$p]['n']='Tambahan *';
- echo "\n===Tambahan *\n";
- $t1 = microtime(true);
- $m1=memory_get_usage();
- $a=_INPUT;$b='';for($i=strlen($a);$i>0;$i--){$b.=$a[$i-1];echo strrev($b)."$b\n";}
- $m2=memory_get_usage();
- $t2 = microtime(true);
- $dt[$p]['t']=$t2-$t1;
- $dt[$p]['m']=$m2-$m1;
- echo "Makan waktu: ".($t2 - $t1)." microsecond\n";
- echo "Makan memory: ".($m2 - $m1)." bytes\n";
- unset($a);
- unset($m1);
- unset($m2);
- unset($i);
- unset($b);
- unset($hasil);
- //============================
- echo "===\nGRAND RESULT\n";
- foreach ($dt as $key => $row) {
- $_name[$key] = $row['n'];
- $_time[$key] = $row['t'];
- }
- array_multisort($_time, SORT_ASC, $_name, SORT_ASC, $dt);
- $no=1;
- foreach($dt as $data){
- echo str_pad($no,3,' ',STR_PAD_LEFT).". "
- .str_pad($data['n'],44,' ')
- .str_pad($data['t'],24,' ',STR_PAD_LEFT)
- .str_pad($data['m'],8,' ',STR_PAD_LEFT)." bytes"
- ."\n";
- $no++;
- }
- echo "===\n)* modified";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement