New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why does this code take 123 ms vs the excpected 12 ms? #213
Comments
Your benchmark is simply different from mine. See tests/benchmark_sortedlist.py
The size of the SortedList is |
This same test takes 15ms. Why does inserting one reduces performance by 10X ? def test_speed1(data): |
I don’t follow. Needs repro. |
from sortedcontainers import SortedList, SortedSet, SortedDict def test_speed1(data): def test_speed2(data): data = [] sorted_data = SortedList() n_runs=10 |
Speed1 is 14ms |
init() uses Python’s highly optimized sorted() function while add() cannot. |
Thank you. |
#This is running in Pycharm and Conda
from sortedcontainers import SortedList, SortedSet, SortedDict
import timeit
import random
def test_speed(data,sorted_data):
for val in data: #Accessing this is not an issue
sorted_data.add(val)
data = []
numpts = 10 ** 5
for i in range(numpts):
data.append(random.random())
print(f'Num of pts:{len(data)}')
sorted_data = SortedList()
n_runs=10
result = timeit.timeit(stmt='test_speed(data,sorted_data)', globals=globals(), number=n_runs)
print(f'Speed is {1000*result/n_runs:0.0f}ms')
The text was updated successfully, but these errors were encountered: