Better performance calculating the dot product and the length of a vector