Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // include('database.php');
- ?>
- <html>
- <head>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
- </head>
- <body>
- <form action="#" method="post">
- <div class="container-fluid no-padding">
- <div class="row text-center no-padding">
- <div class="col-lg-12">
- <div class="row text-center no-padding">
- <div class="col-lg-12">
- <h3>Wpisz kod PHP: </h3>
- <textarea name="textarea" id="textarea"></textarea>
- </div>
- <div class="col-lg-12">
- <input type="submit" name="submit" id="submit" class="btn btn-primary " value="Wynik"/>
- </div>
- </div>
- </div>
- <div class="col-lg-12">
- <div class="row text-center" >
- <div class="col-lg-12">
- <div class="header-table1">
- </div>
- <?php
- if(isset($_POST["submit"]) && ($_POST["textarea"] != ''))
- {
- $servername = "localhost";
- $username = "phpmyadmin";
- $password = "COnexant270392";
- $dbname = "benchmark";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $head="";
- $tail="";
- $tx=$_POST["textarea"];
- if(strpos($tx, 'function') !== false){
- $head=substr($tx,0,strpos($tx, 'function')-1);
- $tail=substr($tx,strpos($tx, 'function'));
- echo "Word Found!";
- } else{
- $head=$tx;
- $tail="";
- echo "Word Not Found!";
- }
- //Zapis pobranego kodu do pliku
- $text = '';
- if($tail!="")
- $text .=$tail;
- $text .='
- $time_start = microtime(true);
- ';
- $text .= $head;
- $text .= '
- $time_end = microtime(true);
- $temp_time = $time_end - $time_start;
- $format_time = number_format($temp_time, 6);
- $t = $format_time * 1000;';
- $fp = fopen("test.php", "w");
- fputs($fp, $text);
- fclose($fp);
- $time_tab = array();
- $sum = 0;
- $deviation_sum = 0;
- //Wykonanie 20 pomiarow predkosci wykonywania sie kodu wraz z zapisem ich do bazy w tabeli ,,output''
- for($test_value=0; $test_value<20; $test_value++)
- {
- ob_start();
- eval(file_get_contents('test.php'));
- ob_end_clean();
- $time_tab[] = $t;
- $sum = $sum + $time_tab[$test_value];
- $sql= "UPDATE `output` SET `time` = '$t' WHERE `output`.`id` = $test_value+1";
- if ($conn->query($sql) !== TRUE)
- {
- echo 'error';
- }
- }
- //Wynik sredniej arytmetycznej pomiarow
- $arithmetic = $sum/20;
- //print_r($time_tab);
- //print_r($aritdmetic);
- //Wyliczenie odchylenia standardowego
- for($test_value=0; $test_value<20; $test_value++)
- {
- $deviation_sum = $deviation_sum + pow(($time_tab[$test_value]-$arithmetic), 2);
- }
- $temp_deviation = $deviation_sum/20;
- $deviation = number_format($temp_deviation, 9);
- //echo "Odchylenie:";
- //print_r($deviation);
- //Zapisanie odchylenia oraz sredniej do bazy w tabeli ,,result''
- $sql= "INSERT INTO `result` (`id`, `arithmetic`, `deviation`) VALUES (NULL, $arithmetic, $deviation)";
- if ($conn->query($sql) !== TRUE)
- {
- echo 'error';
- }
- $conn->close();
- $table = '<h3>Na podstawie 20 pomiarów czasów wczytywania się twojego kodu</h3><div class="tables"><div><table class="table table-bordered">';
- $table .= '<tr>';
- $table .= '<td scope="col">';
- $table .= 'Nr pomiaru';
- $table .= '</td scope="col">';
- $table .= '<td scope="col">';
- $table .= 'Wynik [ms]';
- $table .= '</td scope="col">';
- for($t=0; $t<10; $t++)
- {
- $table .= '<tr>';
- $table .= '<td scope="col">';
- $table .= $t+1;
- $table .= '</td scope="col">';
- $table .= '<td scope="col">';
- $table .= $time_tab[$t];
- $table .= '</td scope="col">';
- }
- $table .= '</table></div>';
- $table .= '<div><table class="table table-bordered">';
- $table .= '<tr>';
- $table .= '<td scope="col">';
- $table .= 'Nr pomiaru';
- $table .= '</td scope="col">';
- $table .= '<td scope="col">';
- $table .= 'Wynik [ms]';
- $table .= '</td scope="col">';
- for($t=10; $t<20; $t++)
- {
- $table .= '<tr>';
- $table .= '<td scope="col">';
- $table .= $t+1;
- $table .= '</td scope="col">';
- $table .= '<td scope="col">';
- $table .= $time_tab[$t];
- $table .= '</td scope="col">';
- }
- $table .= '</table></div></div>';
- echo $table;
- $table_result = '<h3>została obliczona średnia oraz odchylenie standardowe</h3><div class="tables"><div><table class="table table-bordered">';
- $table_result .= '<tr>';
- $table_result .= '<td scope="col">';
- $table_result .= 'Średnia pomiarów [ms]';
- $table_result .= '</td scope="col">';
- $table_result .= '<td scope="col">';
- $table_result .= 'Odchylenie standardowe';
- $table_result .= '</td scope="col">';
- $table_result .= '<tr>';
- $table_result .= '<td scope="col">';
- $table_result .= $arithmetic;
- $table_result .= '</td scope="col">';
- $table_result .= '<td scope="col">';
- $table_result .= $deviation;
- $table_result .= '</td scope="col">';
- $table_result .= '</table></div></div></div>';
- echo $table_result;
- $your_result = '<div class="col-lg-12">';
- $your_result .= '<div id="result"><h1>Twój wynik to:</h1>';
- $your_result .= '<h3>';
- $your_result .= $arithmetic;
- $your_result .= ' ms</h3></div>';
- echo $your_result;
- }
- ?>
- </div>
- </div>
- </div>
- </div>
- </form>
- </body>
- </html>
- <style>
- .container-fluid {
- padding: 20px !important;
- }
- textarea {
- width: 500px;
- height: 80%;
- border-radius: 5px;
- font-size: 20px;
- }
- #submit {
- margin: 20px;
- }
- .header-table1 h1 {
- font-size: 35px;
- }
- table {
- width: 200px !important;
- text-align: center;
- }
- .tables {
- display: flex;
- justify-content: center;
- }
- .tables div{
- }
- h3 {
- margin: 0; padding: 0;
- padding-left: 20px;
- padding-right: 20px;
- margin-bottom: 20px;
- margin-top: 30px;
- }
- #result {
- color: green;
- }
- .no-padding {
- margin: 0 !important;
- padding: 0 !important;
- }
- </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement