benchmark.py 文件源码

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

项目:toasted-marshmallow 作者: lyft 项目源码 文件源码
def run_timeit(quotes, iterations, repeat, jit=False, load=False,
               cython=False, profile=False):
    quotes_schema = QuoteSchema(many=True)
    if jit:
        if cython:
            quotes_schema.jit = CythonJit
        else:
            quotes_schema.jit = Jit
    if profile:
        profile = cProfile.Profile()
        profile.enable()
    dumped_quotes = quotes_schema.dump(quotes).data
    gc.collect()

    if load:
        def marshmallow_func():
            quotes_schema.load(dumped_quotes, many=True)
    else:
        def marshmallow_func():
            quotes_schema.dump(quotes)

    best = min(timeit.repeat(marshmallow_func,
                             'gc.enable()',
                             number=iterations,
                             repeat=repeat))
    if profile:
        profile.disable()
        file_name = 'optimized.pprof' if jit else 'original.pprof'
        profile.dump_stats(file_name)

    usec = best * 1e6 / iterations
    return usec
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号