Added O(1) solution from Jeremy and added how to track performance of a function.