1. import java.io.BufferedReader;
  2. import java.io.FileReader;
  3. import java.io.IOException;
  4. import java.util.logging.Logger;
  5. public class FilePerformance {
  6. private static final Logger logger = Logger.getLogger(FilePerformance.class.getName());
  7. public static void measureFilePerformance(String filePath) {
  8. logger.info("Starting file performance measurement for: " + filePath);
  9. long startTime = System.nanoTime();
  10. try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
  11. String line;
  12. while ((line = reader.readLine()) != null) {
  13. // Process each line (simulate a short-lived task)
  14. // In a real scenario, perform your desired operation here.
  15. // For this example, we just consume the line.
  16. processLine(line);
  17. }
  18. } catch (IOException e) {
  19. logger.error("Error reading file: " + e.getMessage(), e);
  20. }
  21. long endTime = System.nanoTime();
  22. long duration = (endTime - startTime) / 1_000_000; // Duration in milliseconds
  23. logger.info("File performance measurement complete for: " + filePath);
  24. logger.info("Total duration: " + duration + " ms");
  25. }
  26. private static void processLine(String line) {
  27. // Simulate a short-lived task
  28. // Replace with your actual processing logic.
  29. //logger.info("Processing line: " + line);
  30. }
  31. public static void main(String[] args) {
  32. if (args.length != 1) {
  33. logger.severe("Usage: java FilePerformance <file_path>");
  34. System.exit(1);
  35. }
  36. String filePath = args[0];
  37. measureFilePerformance(filePath);
  38. }
  39. }

Add your comment