Calculate various string metrics efficiently.