Advertisement
caparol6991

Untitled

Feb 5th, 2020
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.21 KB | None | 0 0
  1. <?php
  2. // include('database.php');
  3. ?>
  4.  
  5. <html>
  6. <head>
  7. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  8. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
  9. </head>
  10. <body>
  11. <form action="#" method="post">
  12. <div class="container-fluid no-padding">
  13. <div class="row text-center no-padding">
  14. <div class="col-lg-12">
  15. <div class="row text-center no-padding">
  16. <div class="col-lg-12">
  17. <h3>Wpisz kod PHP: </h3>
  18. <textarea name="textarea" id="textarea"></textarea>
  19. </div>
  20. <div class="col-lg-12">
  21. <input type="submit" name="submit" id="submit" class="btn btn-primary " value="Wynik"/>
  22. </div>
  23. </div>
  24. </div>
  25. <div class="col-lg-12">
  26. <div class="row text-center" >
  27. <div class="col-lg-12">
  28. <div class="header-table1">
  29. </div>
  30. <?php
  31. if(isset($_POST["submit"]) && ($_POST["textarea"] != ''))
  32. {
  33. $servername = "localhost";
  34. $username = "phpmyadmin";
  35. $password = "COnexant270392";
  36. $dbname = "benchmark";
  37.  
  38. // Create connection
  39. $conn = new mysqli($servername, $username, $password, $dbname);
  40. // Check connection
  41. if ($conn->connect_error) {
  42. die("Connection failed: " . $conn->connect_error);
  43. }
  44. $head="";
  45. $tail="";
  46. $tx=$_POST["textarea"];
  47. if(strpos($tx, 'function') !== false){
  48. $head=substr($tx,0,strpos($tx, 'function')-1);
  49. $tail=substr($tx,strpos($tx, 'function'));
  50. echo "Word Found!";
  51. } else{
  52. $head=$tx;
  53. $tail="";
  54. echo "Word Not Found!";
  55. }
  56. //Zapis pobranego kodu do pliku
  57. $text = '';
  58.  
  59. if($tail!="")
  60. $text .=$tail;
  61.  
  62. $text .='
  63. $time_start = microtime(true);
  64. ';
  65.  
  66. $text .= $head;
  67.  
  68. $text .= '
  69. $time_end = microtime(true);
  70. $temp_time = $time_end - $time_start;
  71. $format_time = number_format($temp_time, 6);
  72. $t = $format_time * 1000;';
  73.  
  74. $fp = fopen("test.php", "w");
  75. fputs($fp, $text);
  76. fclose($fp);
  77.  
  78. $time_tab = array();
  79. $sum = 0;
  80. $deviation_sum = 0;
  81.  
  82. //Wykonanie 20 pomiarow predkosci wykonywania sie kodu wraz z zapisem ich do bazy w tabeli ,,output''
  83. for($test_value=0; $test_value<20; $test_value++)
  84. {
  85.  
  86.  
  87. ob_start();
  88. eval(file_get_contents('test.php'));
  89. ob_end_clean();
  90.  
  91. $time_tab[] = $t;
  92. $sum = $sum + $time_tab[$test_value];
  93.  
  94. $sql= "UPDATE `output` SET `time` = '$t' WHERE `output`.`id` = $test_value+1";
  95.  
  96. if ($conn->query($sql) !== TRUE)
  97. {
  98. echo 'error';
  99. }
  100. }
  101.  
  102. //Wynik sredniej arytmetycznej pomiarow
  103. $arithmetic = $sum/20;
  104. //print_r($time_tab);
  105. //print_r($aritdmetic);
  106.  
  107. //Wyliczenie odchylenia standardowego
  108. for($test_value=0; $test_value<20; $test_value++)
  109. {
  110. $deviation_sum = $deviation_sum + pow(($time_tab[$test_value]-$arithmetic), 2);
  111. }
  112.  
  113. $temp_deviation = $deviation_sum/20;
  114. $deviation = number_format($temp_deviation, 9);
  115. //echo "Odchylenie:";
  116. //print_r($deviation);
  117.  
  118. //Zapisanie odchylenia oraz sredniej do bazy w tabeli ,,result''
  119. $sql= "INSERT INTO `result` (`id`, `arithmetic`, `deviation`) VALUES (NULL, $arithmetic, $deviation)";
  120. if ($conn->query($sql) !== TRUE)
  121. {
  122. echo 'error';
  123. }
  124.  
  125. $conn->close();
  126.  
  127. $table = '<h3>Na podstawie 20 pomiarów czasów wczytywania się twojego kodu</h3><div class="tables"><div><table class="table table-bordered">';
  128. $table .= '<tr>';
  129. $table .= '<td scope="col">';
  130. $table .= 'Nr pomiaru';
  131. $table .= '</td scope="col">';
  132.  
  133. $table .= '<td scope="col">';
  134. $table .= 'Wynik [ms]';
  135. $table .= '</td scope="col">';
  136. for($t=0; $t<10; $t++)
  137. {
  138. $table .= '<tr>';
  139. $table .= '<td scope="col">';
  140. $table .= $t+1;
  141. $table .= '</td scope="col">';
  142.  
  143. $table .= '<td scope="col">';
  144. $table .= $time_tab[$t];
  145. $table .= '</td scope="col">';
  146. }
  147.  
  148. $table .= '</table></div>';
  149.  
  150. $table .= '<div><table class="table table-bordered">';
  151. $table .= '<tr>';
  152. $table .= '<td scope="col">';
  153. $table .= 'Nr pomiaru';
  154. $table .= '</td scope="col">';
  155.  
  156. $table .= '<td scope="col">';
  157. $table .= 'Wynik [ms]';
  158. $table .= '</td scope="col">';
  159. for($t=10; $t<20; $t++)
  160. {
  161. $table .= '<tr>';
  162. $table .= '<td scope="col">';
  163. $table .= $t+1;
  164. $table .= '</td scope="col">';
  165.  
  166. $table .= '<td scope="col">';
  167. $table .= $time_tab[$t];
  168. $table .= '</td scope="col">';
  169. }
  170.  
  171. $table .= '</table></div></div>';
  172. echo $table;
  173.  
  174. $table_result = '<h3>została obliczona średnia oraz odchylenie standardowe</h3><div class="tables"><div><table class="table table-bordered">';
  175. $table_result .= '<tr>';
  176. $table_result .= '<td scope="col">';
  177. $table_result .= 'Średnia pomiarów [ms]';
  178. $table_result .= '</td scope="col">';
  179.  
  180. $table_result .= '<td scope="col">';
  181. $table_result .= 'Odchylenie standardowe';
  182. $table_result .= '</td scope="col">';
  183.  
  184. $table_result .= '<tr>';
  185. $table_result .= '<td scope="col">';
  186. $table_result .= $arithmetic;
  187. $table_result .= '</td scope="col">';
  188.  
  189. $table_result .= '<td scope="col">';
  190. $table_result .= $deviation;
  191. $table_result .= '</td scope="col">';
  192.  
  193. $table_result .= '</table></div></div></div>';
  194. echo $table_result;
  195.  
  196. $your_result = '<div class="col-lg-12">';
  197. $your_result .= '<div id="result"><h1>Twój wynik to:</h1>';
  198. $your_result .= '<h3>';
  199. $your_result .= $arithmetic;
  200. $your_result .= ' ms</h3></div>';
  201. echo $your_result;
  202. }
  203. ?>
  204.  
  205. </div>
  206. </div>
  207. </div>
  208. </div>
  209. </form>
  210. </body>
  211. </html>
  212.  
  213. <style>
  214.  
  215. .container-fluid {
  216. padding: 20px !important;
  217. }
  218.  
  219. textarea {
  220. width: 500px;
  221. height: 80%;
  222. border-radius: 5px;
  223. font-size: 20px;
  224. }
  225.  
  226. #submit {
  227. margin: 20px;
  228. }
  229.  
  230.  
  231. .header-table1 h1 {
  232. font-size: 35px;
  233.  
  234. }
  235.  
  236. table {
  237. width: 200px !important;
  238. text-align: center;
  239. }
  240.  
  241. .tables {
  242. display: flex;
  243. justify-content: center;
  244. }
  245.  
  246. .tables div{
  247.  
  248. }
  249.  
  250. h3 {
  251. margin: 0; padding: 0;
  252. padding-left: 20px;
  253. padding-right: 20px;
  254. margin-bottom: 20px;
  255. margin-top: 30px;
  256. }
  257.  
  258. #result {
  259. color: green;
  260. }
  261.  
  262. .no-padding {
  263. margin: 0 !important;
  264. padding: 0 !important;
  265. }
  266.  
  267. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement