caparol6991

Untitled

Feb 5th, 2020
174
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 = '<?php
  58. ';
  59.  
  60. if($tail!="")
  61. $text .=$tail;
  62.  
  63. $text .='
  64. $time_start = microtime(true);
  65. ';
  66.  
  67. $text .= $head;
  68.  
  69. $text .= '
  70. $time_end = microtime(true);
  71. $temp_time = $time_end - $time_start;
  72. $format_time = number_format($temp_time, 6);
  73. $t = $format_time * 1000;
  74. ?>';
  75.  
  76. $fp = fopen("test.php", "w");
  77. fputs($fp, $text);
  78. fclose($fp);
  79.  
  80. $time_tab = array();
  81. $sum = 0;
  82. $deviation_sum = 0;
  83.  
  84. //Wykonanie 20 pomiarow predkosci wykonywania sie kodu wraz z zapisem ich do bazy w tabeli ,,output''
  85.  
  86. for($test_value=0; $test_value<20; $test_value++)
  87. {
  88. ob_start();
  89. require_once('test.php');
  90. ob_end_clean();
  91.  
  92. $time_tab[] = $t;
  93. $sum = $sum + $time_tab[$test_value];
  94.  
  95. $sql= "UPDATE `output` SET `time` = '$t' WHERE `output`.`id` = $test_value+1";
  96.  
  97. if ($conn->query($sql) !== TRUE)
  98. {
  99. echo 'error';
  100. }
  101. }
  102.  
  103. //Wynik sredniej arytmetycznej pomiarow
  104. $arithmetic = $sum/20;
  105. //print_r($time_tab);
  106. //print_r($aritdmetic);
  107.  
  108. //Wyliczenie odchylenia standardowego
  109. for($test_value=0; $test_value<20; $test_value++)
  110. {
  111. $deviation_sum = $deviation_sum + pow(($time_tab[$test_value]-$arithmetic), 2);
  112. }
  113.  
  114. $temp_deviation = $deviation_sum/20;
  115. $deviation = number_format($temp_deviation, 9);
  116. //echo "Odchylenie:";
  117. //print_r($deviation);
  118.  
  119. //Zapisanie odchylenia oraz sredniej do bazy w tabeli ,,result''
  120. $sql= "INSERT INTO `result` (`id`, `arithmetic`, `deviation`) VALUES (NULL, $arithmetic, $deviation)";
  121. if ($conn->query($sql) !== TRUE)
  122. {
  123. echo 'error';
  124. }
  125.  
  126. $conn->close();
  127.  
  128. $table = '<h3>Na podstawie 20 pomiarów czasów wczytywania się twojego kodu</h3><div class="tables"><div><table class="table table-bordered">';
  129. $table .= '<tr>';
  130. $table .= '<td scope="col">';
  131. $table .= 'Nr pomiaru';
  132. $table .= '</td scope="col">';
  133.  
  134. $table .= '<td scope="col">';
  135. $table .= 'Wynik [ms]';
  136. $table .= '</td scope="col">';
  137. for($t=0; $t<10; $t++)
  138. {
  139. $table .= '<tr>';
  140. $table .= '<td scope="col">';
  141. $table .= $t+1;
  142. $table .= '</td scope="col">';
  143.  
  144. $table .= '<td scope="col">';
  145. $table .= $time_tab[$t];
  146. $table .= '</td scope="col">';
  147. }
  148.  
  149. $table .= '</table></div>';
  150.  
  151. $table .= '<div><table class="table table-bordered">';
  152. $table .= '<tr>';
  153. $table .= '<td scope="col">';
  154. $table .= 'Nr pomiaru';
  155. $table .= '</td scope="col">';
  156.  
  157. $table .= '<td scope="col">';
  158. $table .= 'Wynik [ms]';
  159. $table .= '</td scope="col">';
  160. for($t=10; $t<20; $t++)
  161. {
  162. $table .= '<tr>';
  163. $table .= '<td scope="col">';
  164. $table .= $t+1;
  165. $table .= '</td scope="col">';
  166.  
  167. $table .= '<td scope="col">';
  168. $table .= $time_tab[$t];
  169. $table .= '</td scope="col">';
  170. }
  171.  
  172. $table .= '</table></div></div>';
  173. echo $table;
  174.  
  175. $table_result = '<h3>została obliczona średnia oraz odchylenie standardowe</h3><div class="tables"><div><table class="table table-bordered">';
  176. $table_result .= '<tr>';
  177. $table_result .= '<td scope="col">';
  178. $table_result .= 'Średnia pomiarów [ms]';
  179. $table_result .= '</td scope="col">';
  180.  
  181. $table_result .= '<td scope="col">';
  182. $table_result .= 'Odchylenie standardowe';
  183. $table_result .= '</td scope="col">';
  184.  
  185. $table_result .= '<tr>';
  186. $table_result .= '<td scope="col">';
  187. $table_result .= $arithmetic;
  188. $table_result .= '</td scope="col">';
  189.  
  190. $table_result .= '<td scope="col">';
  191. $table_result .= $deviation;
  192. $table_result .= '</td scope="col">';
  193.  
  194. $table_result .= '</table></div></div></div>';
  195. echo $table_result;
  196.  
  197. $your_result = '<div class="col-lg-12">';
  198. $your_result .= '<div id="result"><h1>Twój wynik to:</h1>';
  199. $your_result .= '<h3>';
  200. $your_result .= $arithmetic;
  201. $your_result .= ' ms</h3></div>';
  202. echo $your_result;
  203. }
  204. ?>
  205.  
  206. </div>
  207. </div>
  208. </div>
  209. </div>
  210. </form>
  211. </body>
  212. </html>
  213.  
  214. <style>
  215.  
  216. .container-fluid {
  217. padding: 20px !important;
  218. }
  219.  
  220. textarea {
  221. width: 500px;
  222. height: 80%;
  223. border-radius: 5px;
  224. font-size: 20px;
  225. }
  226.  
  227. #submit {
  228. margin: 20px;
  229. }
  230.  
  231.  
  232. .header-table1 h1 {
  233. font-size: 35px;
  234.  
  235. }
  236.  
  237. table {
  238. width: 200px !important;
  239. text-align: center;
  240. }
  241.  
  242. .tables {
  243. display: flex;
  244. justify-content: center;
  245. }
  246.  
  247. .tables div{
  248.  
  249. }
  250.  
  251. h3 {
  252. margin: 0; padding: 0;
  253. padding-left: 20px;
  254. padding-right: 20px;
  255. margin-bottom: 20px;
  256. margin-top: 30px;
  257. }
  258.  
  259. #result {
  260. color: green;
  261. }
  262.  
  263. .no-padding {
  264. margin: 0 !important;
  265. padding: 0 !important;
  266. }
  267.  
  268. </style>
RAW Paste Data