https://stackoverflow.com/questions/58810778/what-is-the-efficiency-of-pythons-list-slicing
https://github.com/LetMeFly666/LeetCode/commit/194a7278af8a1a8ebeff0c74e3cf800bd96178d4
| ''' | |
| Author: LetMeFly | |
| Date: 2024-02-23 11:22:26 | |
| LastEditors: LetMeFly | |
| LastEditTime: 2024-02-23 11:25:03 | |
| ''' | |
| import time | |
| # pop(last element) | |
| start = time.time() | |
| a = [0 for _ in range(100000)] | |
| while a: | |
| a.pop() | |
| end = time.time() | |
| print(f'pop consume: {end - start}s') | |
| # slice(first element) | |
| start = time.time() | |
| a = [0 for _ in range(100000)] | |
| while a: | |
| a = a[1:] | |
| end = time.time() | |
| print(f'slice consume: {end - start}s') |
| pop consume: 0.008001089096069336s | |
| slice consume: 14.755402326583862s |