def size_of_varint_1(value):
    """ Number of bytes needed to encode an integer in variable-length format.
    """
    value = (value << 1) ^ (value >> 63)
    res = 0
    while True:
        res += 1
        value = value >> 7
        if value == 0:
            break
    return res
 Number of bytes needed to encode an integer in variable-length format.
    
kafka/benchmarks/varint_speed.py