Advertisement
IMustRemainUnknown

Sorting Algorithm Speed Test

Dec 18th, 2023
649
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | Source Code | 0 0
  1. import time
  2.  
  3.  
  4. # Your sorting algorithm function
  5. def my_sorting_algorithm(arr):
  6.     # Your sorting algorithm implementation here
  7.     pass
  8.  
  9.  
  10. # Generate your test data
  11. data = [4, 2, 89, 12, 6, 32, 17, 29, 8, 1]
  12.  
  13. # Number of repetitions to get a more accurate measurement
  14. num_repetitions = 500000
  15.  
  16. # Measure your sorting algorithm's performance
  17. total_execution_time = 0
  18.  
  19. for _ in range(num_repetitions):
  20.     start_time = time.time()
  21.     my_sorting_algorithm(data.copy())  # Make a copy to ensure the original data is not sorted
  22.     end_time = time.time()
  23.     total_execution_time += end_time - start_time
  24.  
  25. average_execution_time = (total_execution_time / num_repetitions) * 1000  # Convert to milliseconds
  26. print(f"Your Algorithm Average Execution Time: {average_execution_time:.6f} milliseconds")
  27.  
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement