Skip to content

Commit 7413ef3

Browse files
committed
Add performance measurement to file processing
Refactored the file handling function to include processing time measurement. Now, the exact time it takes to process an uploaded file is being captured and displayed in console logs. This allows for useful insights into the execution duration, potentially highlighting areas for optimization in the file processing methods. No functional changes are introduced with this update.
1 parent 31cfa4f commit 7413ef3

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

src/App.ts

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,33 @@ export default class App {
4848
}
4949
}
5050

51-
/**
52-
* Handles the file upload event.
53-
* @param event - The file upload event.
54-
*/
55-
private async handleFileUpload(event: Event): Promise<void> {
56-
const input = event.target as HTMLInputElement;
57-
if (input.files && input.files.length > 0) {
58-
const file = input.files[0];
59-
this.hideFileInput();
60-
this.showLoadingSpinner();
61-
await this.processFile(file);
62-
this.hideLoadingSpinner();
63-
this.showSuccessMessage(this.showFileInput.bind(this));
64-
input.value = ''; // Clear the input field
65-
}
51+
/**
52+
* Handles the file upload event.
53+
* @param event - The file upload event.
54+
*/
55+
private async handleFileUpload(event: Event): Promise<void> {
56+
const input = event.target as HTMLInputElement;
57+
if (input.files && input.files.length > 0) {
58+
const file = input.files[0];
59+
this.hideFileInput();
60+
this.showLoadingSpinner();
61+
62+
const startTime = performance.now(); // Start time measurement
63+
await this.processFile(file);
64+
const endTime = performance.now(); // End time measurement
65+
66+
this.hideLoadingSpinner();
67+
this.showSuccessMessage(this.showFileInput.bind(this));
68+
input.value = ''; // Clear the input field
69+
70+
const processingTime = (endTime - startTime) / 1000;
71+
const seconds = Math.floor(processingTime);
72+
const milliseconds = Math.floor((processingTime - seconds) * 1000);
73+
74+
console.info(`File processing time: ${seconds} seconds and ${milliseconds} milliseconds`);
6675
}
76+
}
77+
6778

6879
/**
6980
* Processes the uploaded file.

0 commit comments

Comments
 (0)