Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- # Your sorting algorithm function
- def my_sorting_algorithm(arr):
- # Your sorting algorithm implementation here
- pass
- # Generate your test data
- data = [4, 2, 89, 12, 6, 32, 17, 29, 8, 1]
- # Number of repetitions to get a more accurate measurement
- num_repetitions = 500000
- # Measure your sorting algorithm's performance
- total_execution_time = 0
- for _ in range(num_repetitions):
- start_time = time.time()
- my_sorting_algorithm(data.copy()) # Make a copy to ensure the original data is not sorted
- end_time = time.time()
- total_execution_time += end_time - start_time
- average_execution_time = (total_execution_time / num_repetitions) * 1000 # Convert to milliseconds
- print(f"Your Algorithm Average Execution Time: {average_execution_time:.6f} milliseconds")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement