<?php
/**
* Simple form field performance measurement script.
* Designed for non-production environments.
*/
// Define the form fields to measure. Adjust as needed.
$fields = [
'name' => 'Name',
'email' => 'Email',
'message' => 'Message',
'phone' => 'Phone Number'
];
// Function to measure field performance
function measureFieldPerformance($field_name, $data) {
$start_time = microtime(true);
// Validate data (basic check)
if (!empty($data[$field_name])) {
//Simulate some processing
$processed_data = strtoupper(trim($data[$field_name]));
} else {
$processed_data = '';
}
$end_time = microtime(true);
$execution_time = $end_time - $start_time;
return [
'field' => $field_name,
'data' => $data[$field_name],
'execution_time' => number_format($execution_time, 4), // Format to 4 decimal places
'processed_data' => $processed_data
];
}
// Simulate form data (replace with your actual form submission)
$form_data = [
'name' => 'John Doe',
'email' => 'john.doe@example.com',
'message' => 'This is a test message.',
'phone' => '123-456-7890'
];
// Measure performance for each field
$performance_results = [];
foreach ($fields as $field_name => $field_label) {
$result = measureFieldPerformance($field_name, $form_data);
$performance_results[] = $result;
}
// Output the results in a human-readable format
echo "<h2>Form Field Performance Measurement</h2>";
echo "<table border='1'>";
echo "<tr><th>Field</th><th>Data</th><th>Execution Time (s)</th><th>Processed Data</th></tr>";
foreach ($performance_results as $result) {
echo "<tr>";
echo "<td>" . htmlspecialchars($result['field']) . "</td>";
echo "<td>" . htmlspecialchars($result['data']) . "</td>";
echo "<td>" . $result['execution_time'] . "</td>";
echo "<td>" . htmlspecialchars($result['processed_data']) . "</td>";
echo "</tr>";
}
echo "</table>";
?>
Add your comment