def constantTimeCompare(val1, val2):
    """
    This function compares 2 values in constant time if they are the same
    length. It will return false immediately if they are not the same length.

    This function has a margin of error of around 6 microseconds

    Args:
        :param val1: The first value to compare
        :param val2: The second value to compare

    Returns:
        bool: True if the values are the same, false otherwise
    """
    if(len(val2) is not len(val1)):
        return False

    if(not isinstance(val1, bytes)):
        val1 = val1.encode()

    if(not isinstance(val2, bytes)):
        val2 = val2.encode()

    result = 0
    for x, y in zip(val1, val2):
        result |= x ^ y

    return result == 0