I was working on a problem to check on a large array of integers to check whether it is a part of another array or not. Both the arrays have unique elements, but not in sorted order. So there are multiple ways possible to this, but I was not sure that which approach is most efficient. I searched for this but couldn’t come across anything valuable. Then I decided to benchmark whole approach by my self.
If we have array which is already converted in Set then susbet comparison is fastet(1.7 times) than second rank method. But if we consider conversion of Array into sets then it is the slowest method.
In above code snippet we have compared four ways to compare arrays with each other.
Subscribe to Ruby in Rails
Get the latest posts delivered right to your inbox