Extracting cost recurrences from sequential and parallel functional programs