utils.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:python-pool-performance 作者: JohnStarich 项目源码 文件源码
def bytes_for_humans(byte_count: int):
    # Get power of two directly from floating point exponent bits (mantissa)
    power_of_2 = frexp(byte_count)[1] - 1
    binary_multiple = power_of_2 // 10
    # If too big, represent in largest form
    if binary_multiple >= len(byte_names):
        binary_multiple = len(byte_names) - 1
    # Gets the magnitude of the most significant multiple of 1024
    impercise_magnitude = byte_count // (1 << (binary_multiple * 10))
    # If less than 1024B, just return number of bytes
    if binary_multiple == 0:
        return str(impercise_magnitude) + ' B'
    return str(impercise_magnitude) + ' ' \
        + byte_names[binary_multiple - 1] + 'B'
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号