unit_test_performance.py 文件源码

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

项目:ci_edit 作者: google 项目源码 文件源码
def test_split_insert(self):
    return  # Remove to enable test (disabled due to running time).
    # This tests a performance assumption. If this test fails, the program
    # should still work fine, but it may not run as fast as it could by using
    # different assumptions.
    #
    # With frequent splitting the performance reverses.
    for lineCount in (100, 1000, 5000):
      half = lineCount / 2
      a = timeit(r'''data2 = data1.split('\n'); \
              data2[%s] = data2[%s][:50] + "x" + data2[%s][50:]; \
              ''' % (half, half, half),
          setup=r'''data1 = ("a" * 100 + '\n') * %s''' % (lineCount,),
          number=10000)
      b = timeit('data1 = data1[:%s] + "x" + data1[%s:]' % (half, half),
          setup=r'''data1 = ("a" * 100 + '\n') * %s''' % (lineCount,),
          number=10000)
      print "\n%9s: %s %s" % (lineCount, a, b)
      self.assertGreater(a, b)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号