美文网首页
Measure execution time of small

Measure execution time of small

作者: import_hello | 来源:发表于2018-10-10 22:12 被阅读0次
    # The "timeit" module lets you measure the execution
    # time of small bits of Python code
    
    >>> import timeit
    >>> timeit.timeit('"-".join(str(n) for n in range(100))',
                      number=10000)
    
    0.3412662749997253
    
    >>> timeit.timeit('"-".join([str(n) for n in range(100)])',
                      number=10000)
    
    0.2996307989997149
    
    >>> timeit.timeit('"-".join(map(str, range(100)))',
                      number=10000)
    
    0.24581470699922647
    

    相关文章

      网友评论

          本文标题:Measure execution time of small

          本文链接:https://www.haomeiwen.com/subject/kmlboftx.html