gpt-4.1-2025-04-14· OpenAI
LMArena Human Preference 140K
How to make python program output time it took to run it before closing?
- User
How to make python program output time it took to run it before closing?
- Assistant
To make a Python program output the time it took to run before closing, you can use the
timemodule to record the start and end times, then print the elapsed time at the end of your script.Here’s a simple way to do it:
import time start_time = time.time() # Record the start time # --- Your program code goes here --- # For example: for i in range(1000000): pass # --- End of your program code --- end_time = time.time() # Record the end time elapsed_time = end_time - start_time print(f"Program executed in {elapsed_time:.4f} seconds.")
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.