def _cmp_sample(a, b):
    """Compare two samples.

    First compare the resource ids. Compare the timestamps if the
    resource ids are the same.

    :param a: First sample
    :param b: Second sample
    :return: Result of cmp function.
    :rtype: Integer
    """
    result = cmp(a.resource_id, b.resource_id)
    if result == 0:
        result = cmp(a.timestamp, b.timestamp)
    return result