1. <?php
  2. /**
  3. * Simple form field performance measurement script.
  4. * Designed for non-production environments.
  5. */
  6. // Define the form fields to measure. Adjust as needed.
  7. $fields = [
  8. 'name' => 'Name',
  9. 'email' => 'Email',
  10. 'message' => 'Message',
  11. 'phone' => 'Phone Number'
  12. ];
  13. // Function to measure field performance
  14. function measureFieldPerformance($field_name, $data) {
  15. $start_time = microtime(true);
  16. // Validate data (basic check)
  17. if (!empty($data[$field_name])) {
  18. //Simulate some processing
  19. $processed_data = strtoupper(trim($data[$field_name]));
  20. } else {
  21. $processed_data = '';
  22. }
  23. $end_time = microtime(true);
  24. $execution_time = $end_time - $start_time;
  25. return [
  26. 'field' => $field_name,
  27. 'data' => $data[$field_name],
  28. 'execution_time' => number_format($execution_time, 4), // Format to 4 decimal places
  29. 'processed_data' => $processed_data
  30. ];
  31. }
  32. // Simulate form data (replace with your actual form submission)
  33. $form_data = [
  34. 'name' => 'John Doe',
  35. 'email' => 'john.doe@example.com',
  36. 'message' => 'This is a test message.',
  37. 'phone' => '123-456-7890'
  38. ];
  39. // Measure performance for each field
  40. $performance_results = [];
  41. foreach ($fields as $field_name => $field_label) {
  42. $result = measureFieldPerformance($field_name, $form_data);
  43. $performance_results[] = $result;
  44. }
  45. // Output the results in a human-readable format
  46. echo "<h2>Form Field Performance Measurement</h2>";
  47. echo "<table border='1'>";
  48. echo "<tr><th>Field</th><th>Data</th><th>Execution Time (s)</th><th>Processed Data</th></tr>";
  49. foreach ($performance_results as $result) {
  50. echo "<tr>";
  51. echo "<td>" . htmlspecialchars($result['field']) . "</td>";
  52. echo "<td>" . htmlspecialchars($result['data']) . "</td>";
  53. echo "<td>" . $result['execution_time'] . "</td>";
  54. echo "<td>" . htmlspecialchars($result['processed_data']) . "</td>";
  55. echo "</tr>";
  56. }
  57. echo "</table>";
  58. ?>

Add your comment