I had good luck finding a way to achieve intersect() faster on stack overflow with a pre-sorted 1d vector, so I am hoping for the same luck for unique() 😉
Almost 1/4’th of my runtime is spent using unique(). I would like to speed this up, and I can assume it to be 1d pre-sorted vector. Is there any other low-level functions I can use directly to speed this up?
You can simply use
diffto check whether consecutive elements are the same.