3v4l.org

run code in 300+ PHP versions simultaneously
<?php // gráfico normal e invertido com vários gráficos function test_mysql_connection() { $servername = "sql10.freemysqlhosting.net"; $username = "sql10716406"; $password = "14hhtpmHk7"; $dbname = "sql10716406"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); function timestamp_to_formatted_datetime($timestamp_ms, $date_format = 'Y-m-d H:i:s') { $timestamp_s = $timestamp_ms / 1000; return date($date_format, $timestamp_s); } // Check connection if ($conn->connect_error) { return "Connection failed: " . $conn->connect_error; } else { // SQL query to retrieve data $sql = "SELECT * FROM cripto"; $result = $conn->query($sql); if ($result->num_rows > 0) { // Prepare an array to hold data for JavaScript $data_for_js = []; while ($row = $result->fetch_assoc()) { $klinebar = json_decode($row['klinebar'], true); $temp = []; // Process the klines data foreach ($klinebar as $kline) { $timestamp_ms = $kline[0]; $open_price = floatval($kline[1]); $high_price = floatval($kline[2]); $low_price = floatval($kline[3]); $close_price = floatval($kline[4]); // Convert timestamp $dt_object = timestamp_to_formatted_datetime($timestamp_ms); $temp[] = [ 'timestamp' => $dt_object, 'open' => $open_price, 'high' => $high_price, 'low' => $low_price, 'close' => $close_price, ]; } $data_for_js[] = $temp; } // Close connection $conn->close(); // Now, output the JavaScript for Plotly ob_start(); // Start buffering output ?> <script src="https://cdn.plot.ly/plotly-latest.min.js"></script> <script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script> <table> <?php foreach ($data_for_js as $index => $data) { echo "<tr> <td><div id='chartDiv_$index'></div></td> <td><div id='invertedChartDiv_$index'></div></td> <td><div id='renkoChartDiv_$index'></div></td> </tr>"; ?> <script> document.addEventListener('DOMContentLoaded', function() { var data = <?php echo json_encode($data); ?>; var trace = { x: data.map(function(entry) { return entry.timestamp; }), open: data.map(function(entry) { return entry.open; }), high: data.map(function(entry) { return entry.high; }), low: data.map(function(entry) { return entry.low; }), close: data.map(function(entry) { return entry.close; }), // Customize colors increasing: {line: {color: 'black'}}, decreasing: {line: {color: 'red'}}, type: 'candlestick', }; var layout = { dragmode: 'zoom', showlegend: false, xaxis: { rangeslider: { visible: false } }, yaxis: { autorange: true, zeroline: false } }; Plotly.newPlot('chartDiv_<?php echo $index; ?>', [trace], layout); // Create the inverted chart data var invertedData = data.map(function(entry) { return { timestamp: entry.timestamp, open: entry.close, // swap open and close high: entry.low, // swap high and low low: entry.high, // swap high and low close: entry.open // swap open and close }; }); var invertedTrace = { x: invertedData.map(function(entry) { return entry.timestamp; }), open: invertedData.map(function(entry) { return entry.open; }), high: invertedData.map(function(entry) { return entry.high; }), low: invertedData.map(function(entry) { return entry.low; }), close: invertedData.map(function(entry) { return entry.close; }), // Customize colors increasing: {line: {color: 'black'}}, decreasing: {line: {color: 'red'}}, type: 'candlestick', }; Plotly.newPlot('invertedChartDiv_<?php echo $index; ?>', [invertedTrace], layout); //renko abaixo // Create the Renko chart var renkoData = [{ dataPoints: data.map(function(entry) { return {x: new Date(entry.timestamp), y: [entry.open, entry.high, entry.low, entry.close]}; }) }]; var renkoChart = new CanvasJS.Chart("renkoChartDiv_<?php echo $index; ?>", { title: { text: "Renko Chart", fontFamily: "times new roman" }, zoomEnabled: true, exportEnabled: true, axisY: { includeZero: false, title: "Prices", prefix: "$ " }, axisX: { tickLength: 0, labelFormatter: function(e) { return ""; } } }); renkoChart.options.data = renderRenko(50, renkoData); renkoChart.render(); function renderRenko(brickSize, data) { var newDataPoints = []; var oldValue = data[0].dataPoints[0].y[3]; var difference = 0; var newValue, dataPoint, xValue; for (var i = 1; i < data[0].dataPoints.length; i++) { dataPoint = data[0].dataPoints[i].y[3]; xValue = CanvasJS.formatDate(data[0].dataPoints[i].x, "MMM-YYYY"); difference = dataPoint - oldValue; if (difference > 0 && difference > brickSize) { for (var j = 0; j < Math.floor(difference / brickSize); j++) { newValue = oldValue + brickSize; newDataPoints.push({content: xValue, y: [oldValue, newValue], color: "#86B402"}); oldValue = newValue; } } else if (difference < 0 && Math.abs(difference) > brickSize) { for (var j = 0; j < Math.floor(Math.abs(difference) / brickSize); j++) { newValue = oldValue - brickSize; newDataPoints.push({content: xValue, y: [oldValue, newValue], color: "#C24642"}); oldValue = newValue; } } } var newData = [{ type: "rangeColumn", toolTipContent: "<b>{content}</b> <br> {y[0]} - {y[1]}", dataPoints: newDataPoints }]; return newData; } //renko acima }); </script> <?php } ?> </table> <?php return ob_get_clean(); // Return buffered output } else { $conn->close(); return "Update in progress. Refresh the page in 2 minutes"; } } } ?>

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.4.120.0090.00924.07
8.4.110.0110.01120.94
8.4.100.0100.01118.98
8.4.90.0090.01120.77
8.4.80.0110.00918.66
8.4.70.0110.00619.10
8.4.60.0130.00918.54
8.4.50.0110.01020.13
8.4.40.0130.00719.32
8.4.30.0090.00020.85
8.4.20.0190.00319.53
8.4.10.0000.00919.26
8.3.250.0110.00719.14
8.3.240.0150.00417.14
8.3.230.0040.00516.58
8.3.220.0070.00718.88
8.3.210.0120.00618.27
8.3.200.0040.00516.25
8.3.190.0120.00820.98
8.3.180.0120.00619.09
8.3.170.0130.00618.84
8.3.160.0000.00816.46
8.3.150.0120.00618.60
8.3.140.0080.00018.71
8.3.130.0080.00018.31
8.3.120.0040.01220.59
8.3.110.0080.00416.40
8.3.100.0060.00316.74
8.3.90.0050.00316.61
8.3.80.0380.00930.84
8.3.70.0420.00630.84
8.3.60.0350.01430.84
8.3.50.0110.00730.84
8.3.40.0290.00630.84
8.3.30.0310.00830.84
8.3.20.0270.01230.84
8.3.10.0320.00730.84
8.3.00.0390.00030.84
8.2.290.0060.00222.26
8.2.280.0080.00919.91
8.2.270.0150.00416.85
8.2.260.0110.00016.70
8.2.250.0170.00317.45
8.2.240.0040.01516.98
8.2.230.0000.00920.94
8.2.220.0090.00024.06
8.2.210.0000.00826.77
8.2.200.0080.01230.84
8.2.190.0310.01030.84
8.2.180.0380.01030.84
8.2.170.0440.01230.84
8.2.160.0400.00730.84
8.2.150.0500.00030.84
8.2.140.0310.00930.84
8.2.130.0290.00630.84
8.2.120.0230.01230.84
8.2.110.0370.00330.84
8.2.100.0310.01030.84
8.2.90.0410.00830.84
8.2.80.0420.00430.84
8.2.70.0340.00930.84
8.2.60.0330.00930.84
8.2.50.0300.00730.84
8.2.40.0170.00030.84
8.2.30.0290.01030.84
8.2.20.0240.01430.84
8.2.10.0250.01430.84
8.2.00.0330.00730.84
8.1.330.0110.00721.85
8.1.320.0070.01217.75
8.1.310.0100.00718.16
8.1.300.0030.00620.25
8.1.290.0350.00730.84
8.1.280.0270.01530.84
8.1.270.0340.01430.84
8.1.260.0310.01230.84
8.1.250.0280.00730.84
8.1.240.0290.01030.84
8.1.230.0330.00830.84
8.1.220.0340.00730.84
8.1.210.0310.01030.84
8.1.200.0380.00030.84
8.1.190.0350.00330.84
8.1.180.0230.01030.84
8.1.170.0270.01030.84
8.1.160.0310.00730.84
8.1.150.0280.00930.84
8.1.140.0210.01730.84
8.1.130.0260.00730.84
8.1.120.0270.00330.84
8.1.110.0170.00030.84
8.1.100.0160.00330.84
8.1.90.0410.00330.84
8.1.80.0170.02130.84
8.1.70.0340.00330.84
8.1.60.0340.00730.84
8.1.50.0340.00830.84
8.1.40.0370.00430.84
8.1.30.0390.00330.84
8.1.20.0300.00730.84
8.1.10.0220.00430.84
8.1.00.0170.01530.84

preferences:
26.71 ms | 403 KiB | 5 Q