Advertisement
cdsatrian

hello word

Mar 17th, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.13 KB | None | 0 0
  1. <pre>
  2. <?php
  3. error_reporting(-1);
  4. //============================
  5. define('_INPUT','Hello Word');
  6. //============================
  7. $p=0;
  8. $dt[$p]['n']='Cahya DSN #1';
  9. echo "===Cahya DSN #1\n";
  10. $t1 = microtime(true);
  11. $m1=memory_get_usage();
  12. $input=_INPUT;
  13. $l=strlen($input);
  14. $input.=strrev($input);
  15. for($i=0;$i<$l;$i++) echo substr($input,$l-$i-1,($i+1)*2),"\n";
  16. $m2=memory_get_usage();
  17. $t2 = microtime(true);
  18. $dt[$p]['t']=$t2-$t1;
  19. $dt[$p]['m']=$m2-$m1;
  20. echo "Makan waktu: ".($t2 - $t1)." microsecond\n";
  21. echo "Makan memory: ".($m2 - $m1)." bytes\n";
  22. unset($input);
  23. unset($m1);
  24. unset($m2);
  25. unset($l);
  26. unset($i);
  27. //============================
  28. $p=1;
  29. $dt[$p]['n']='Cahya DSN #2';
  30. echo "===Cahya DSN #2\n";
  31. $t1 = microtime(true);
  32. $m1=memory_get_usage();
  33. $input=_INPUT;
  34. $l=strlen($input);
  35. $input.=strrev($input);
  36. for($i=0;$i<$l;$i++) echo str_pad(substr($input,$l-$i-1,($i+1)*2),$l*2,' ',STR_PAD_BOTH),"\n";
  37. $m2=memory_get_usage();
  38. $t2 = microtime(true);
  39. $dt[$p]['t']=$t2-$t1;
  40. $dt[$p]['m']=$m2-$m1;
  41. echo "Makan waktu: ".($t2 - $t1)." microsecond\n";
  42. echo "Makan memory: ".($m2 - $m1)." bytes\n";
  43. unset($input);
  44. unset($m1);
  45. unset($m2);
  46. unset($l);
  47. unset($i);
  48. //=============================
  49. $p=3;
  50. $dt[$p]['n']='Sandy Racy';
  51. echo "\n===Sandy Racy \n";
  52. $t1 = microtime(true);
  53. $m1=memory_get_usage();
  54. $input=_INPUT;
  55. $n=strlen($input);
  56. for($h=$n;$h>=0;$h--)
  57. {
  58.   for($i=$h;$i<$n;$i++){
  59.     $hasil.=$input[$i];
  60.   }
  61.   for($j=$n;$j>=$h;$j--){
  62.     $hasil.=$input[$j];
  63.   }
  64.   $hasil.="\n";
  65. }
  66. echo $hasil;
  67. $m2=memory_get_usage();
  68. $t2 = microtime(true);
  69. $dt[$p]['t']=$t2-$t1;
  70. $dt[$p]['m']=$m2-$m1;
  71. echo "Makan waktu: ".($t2 - $t1)." microsecond\n";
  72. echo "Makan memory: ".($m2 - $m1)." bytes\n";
  73. unset($input);
  74. unset($m1);
  75. unset($m2);
  76. unset($h);
  77. unset($n);
  78. unset($i);
  79. unset($j);
  80. unset($hasil);
  81. //=============================
  82. $p=4;
  83. $dt[$p]['n']='Sandy racy *';
  84. echo "\n===Sandy Racy *\n";
  85. $t1 = microtime(true);
  86. $m1=memory_get_usage();
  87. $input=_INPUT;
  88. $n=strlen($input);
  89. $hasil='';
  90. for($h=$n-1;$h>=0;$h--)
  91. {
  92.   for($i=$h;$i<$n;$i++){
  93.     $hasil.=$input[$i];
  94.   }
  95.   for($j=$n-1;$j>=$h;$j--){
  96.     $hasil.=$input[$j];
  97.   }
  98.   $hasil.="\n";
  99. }
  100. echo $hasil;
  101. $m2=memory_get_usage();
  102. $t2 = microtime(true);
  103. $dt[$p]['t']=$t2-$t1;
  104. $dt[$p]['m']=$m2-$m1;
  105. echo "Makan waktu: ".($t2 - $t1)." microsecond\n";
  106. echo "Makan memory: ".($m2 - $m1)." bytes\n";
  107. unset($input);
  108. unset($m1);
  109. unset($m2);
  110. unset($h);
  111. unset($n);
  112. unset($i);
  113. unset($j);
  114. unset($hasil);
  115. //============================
  116. $p=5;
  117. $dt[$p]['n']='Nusantara Prasetya Wijaya';
  118. echo "\n===Nusantara Prasetya Wijaya\n";
  119. $t1 = microtime(true);
  120. $m1=memory_get_usage();
  121. $input=_INPUT;
  122. $length=strlen($input);
  123. for($i=1;$i<$length;$i++)
  124. {
  125.   for($f=$length-$i;$f<=$length;$f++) echo $input[$f];
  126.   for($b=$length;$b>=$length-$i;$b--) echo $input[$b];
  127. }
  128. $m2=memory_get_usage();
  129. $t2 = microtime(true);
  130. $dt[$p]['t']=$t2-$t1;
  131. $dt[$p]['m']=$m2-$m1;
  132. echo "Makan waktu: ".($t2 - $t1)." microsecond\n";
  133. echo "Makan memory: ".($m2 - $m1)." bytes\n";
  134. unset($input);
  135. unset($m1);
  136. unset($m2);
  137. unset($length);
  138. unset($i);
  139. unset($f);
  140. unset($b);
  141. //============================
  142. $p=6;
  143. $dt[$p]['n']='Nusantara Prasetya Wijaya *';
  144. echo "\n===Nusantara Prasetya Wijaya *\n";
  145. $t1 = microtime(true);
  146. $m1=memory_get_usage();
  147. $input=_INPUT;
  148. $length=strlen($input);
  149. for($i=0;$i<$length;$i++)
  150. {
  151.   for($f=$length-$i;$f<=$length;$f++) echo $input[$f-1];
  152.   for($b=$length-1;$b>=$length-$i-1;$b--) echo $input[$b];
  153.   echo "\n";
  154. }
  155. $m2=memory_get_usage();
  156. $t2 = microtime(true);
  157. $dt[$p]['t']=$t2-$t1;
  158. $dt[$p]['m']=$m2-$m1;
  159. echo "Makan waktu: ".($t2 - $t1)." microsecond\n";
  160. echo "Makan memory: ".($m2 - $m1)." bytes\n";
  161. unset($input);
  162. unset($m1);
  163. unset($m2);
  164. unset($length);
  165. unset($i);
  166. unset($f);
  167. unset($b);
  168. //============================
  169. $p=7;
  170. $dt[$p]['n']='C Rieqy IfIndefXor PetangatusteluForbidden';
  171. echo "\n=== C Rieqy IfIndefXor PetangatusteluForbidden\n";
  172. $t1 = microtime(true);
  173. $m1=memory_get_usage();
  174. $input=_INPUT;
  175. $len=strlen($input);
  176. $a=$len;
  177. for($c=$len;$c>=0;$c--){
  178.   for($d=$c;$d<$len;$d++){
  179.     echo $input[$d];
  180.   }
  181.   for($b=$len;$b>$a;$b--){
  182.     echo $input[$b-1];
  183.   }
  184.   echo "\n";
  185.   $a++;
  186. }
  187. $m2=memory_get_usage();
  188. $t2 = microtime(true);
  189. $dt[$p]['t']=$t2-$t1;
  190. $dt[$p]['m']=$m2-$m1;
  191. echo "Makan waktu: ".($t2 - $t1)." microsecond\n";
  192. echo "Makan memory: ".($m2 - $m1)." bytes\n";
  193. unset($input);
  194. unset($m1);
  195. unset($m2);
  196. unset($len);
  197. unset($c);
  198. unset($d);
  199. unset($b);
  200. unset($a);
  201. //============================
  202. $p=8;
  203. $dt[$p]['n']='C Rieqy IfIndefXor PetangatusteluForbidden *';
  204. echo "\n=== C Rieqy IfIndefXor PetangatusteluForbidden *\n";
  205. $t1 = microtime(true);
  206. $m1=memory_get_usage();
  207. $input=_INPUT;
  208. $len=strlen($input);
  209. $a=$len;
  210. for($c=$len;$c>=0;$c--){
  211.   for($d=$c;$d<$len;$d++){
  212.     echo $input[$d];
  213.   }
  214.   for($b=$len;$b>$a;$b--){
  215.     echo $input[$b-1];
  216.   }
  217.   echo "\n";
  218.   $a--;
  219. }
  220. $m2=memory_get_usage();
  221. $t2 = microtime(true);
  222. $dt[$p]['t']=$t2-$t1;
  223. $dt[$p]['m']=$m2-$m1;
  224. echo "Makan waktu: ".($t2 - $t1)." microsecond\n";
  225. echo "Makan memory: ".($m2 - $m1)." bytes\n";
  226. unset($input);
  227. unset($m1);
  228. unset($m2);
  229. unset($len);
  230. unset($c);
  231. unset($d);
  232. unset($b);
  233. unset($a);
  234. //============================
  235. $p=9;
  236. $dt[$p]['n']='Alfian Syahputra';
  237. echo "\n===Alfian Syahputra\n";
  238. $t1 = microtime(true);
  239. $m1=memory_get_usage();
  240. $a=_INPUT;
  241. for($i=strlen($a);$i>=0;$i--){
  242.   $b=substr($a,$i);
  243.   echo $b.strrev($b)."\n";
  244. }
  245. $m2=memory_get_usage();
  246. $t2 = microtime(true);
  247. $dt[$p]['t']=$t2-$t1;
  248. $dt[$p]['m']=$m2-$m1;
  249. echo "Makan waktu: ".($t2 - $t1)." microsecond\n";
  250. echo "Makan memory: ".($m2 - $m1)." bytes\n";
  251. unset($a);
  252. unset($m1);
  253. unset($m2);
  254. unset($i);
  255. unset($b);
  256. unset($hasil);
  257. //============================
  258. $p=10;
  259. $dt[$p]['n']='Ruli Armando';
  260. echo "\n===Ruli Armando\n";
  261. $t1 = microtime(true);
  262. $m1=memory_get_usage();
  263. $input=_INPUT;for($s=strrev($input),$i=0,$o='';$c=@$s[$i++];) echo$o="$c$o$c","\n";
  264. $m2=memory_get_usage();
  265. $t2 = microtime(true);
  266. $dt[$p]['t']=$t2-$t1;
  267. $dt[$p]['m']=$m2-$m1;
  268. echo "Makan waktu: ".($t2 - $t1)." microsecond\n";
  269. echo "Makan memory: ".($m2 - $m1)." bytes\n";
  270. unset($input);
  271. unset($m1);
  272. unset($m2);
  273. unset($i);
  274. unset($b);
  275. unset($hasil);
  276. //============================
  277. $p=11;
  278. $dt[$p]['n']='Tambahan *';
  279. echo "\n===Tambahan *\n";
  280. $t1 = microtime(true);
  281. $m1=memory_get_usage();
  282. $a=_INPUT;$b='';for($i=strlen($a);$i>0;$i--){$b.=$a[$i-1];echo strrev($b)."$b\n";}
  283. $m2=memory_get_usage();
  284. $t2 = microtime(true);
  285. $dt[$p]['t']=$t2-$t1;
  286. $dt[$p]['m']=$m2-$m1;
  287. echo "Makan waktu: ".($t2 - $t1)." microsecond\n";
  288. echo "Makan memory: ".($m2 - $m1)." bytes\n";
  289. unset($a);
  290. unset($m1);
  291. unset($m2);
  292. unset($i);
  293. unset($b);
  294. unset($hasil);
  295. //============================
  296. echo "===\nGRAND RESULT\n";
  297. foreach ($dt as $key => $row) {
  298.     $_name[$key] = $row['n'];
  299.     $_time[$key] = $row['t'];
  300. }
  301. array_multisort($_time, SORT_ASC, $_name, SORT_ASC, $dt);
  302. $no=1;
  303. foreach($dt as $data){
  304.   echo str_pad($no,3,' ',STR_PAD_LEFT).". "
  305.       .str_pad($data['n'],44,' ')
  306.       .str_pad($data['t'],24,' ',STR_PAD_LEFT)
  307.       .str_pad($data['m'],8,' ',STR_PAD_LEFT)." bytes"
  308.       ."\n";
  309.   $no++;    
  310. }
  311. echo "===\n)* modified";
  312. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement