Why is builtin sorted() slower for a list containing descending numbers if each number appears twice consecutively?

As alluded to in the comments by btilly and Amadan, this is due to how the Timsort sorting algorithm works. Detailed description of the algorithm is here. Timsort speeds up operation on partially sorted arrays by identifying runs of sorted elements. A run is either “ascending”, which means non-decreasing: a0 <= a1 <= a2 <= … Read more

Keep PostgreSQL from sometimes choosing a bad query plan

If the query planner makes bad decisions it’s mostly one of two things: 1. The statistics are inaccurate. Do you run ANALYZE enough? Also popular in its combined form VACUUM ANALYZE. If autovacuum is on (which is the default in modern-day Postgres), ANALYZE is run automatically. But consider: Are regular VACUUM ANALYZE still recommended under … Read more

Is calling std::vector::size() as fast as reading a variable?

Interesting question. So, what’s going to happened ? Well if you debug with gdb you’ll see something like 3 member variables (names are not accurate): _M_begin: pointer to the first element of the dynamic array _M_end: pointer one past the last element of the dynamic array _M_capacity: pointer one past the last element that could … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)