def safe_compare(val1, val2):
    """
    Compares two strings to each other.
    The time taken is independent of the number of characters that match.

    :param val1: First string for comparison.
    :type val1: :class:`str`

    :param val2: Second string for comparison.
    :type val2: :class:`str`

    :returns: :class:`bool` -- True if the two strings are equal, False otherwise.
    """
    if len(val1) != len(val2):
        return False
    result = 0
    for c1, c2 in zip(val1, val2):
        result |= ord(c1) ^ ord(c2)
    return result == 0
