benchmark.py 文件源码

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

项目:compression-benchmark 作者: sfu-compbio 项目源码 文件源码
def execute(cmd, fin, fout, ferr, exclusive=False, single_thread=False):
    fi = sp.PIPE
    if fin != '':
        fi = open(fin, 'r') 
    fo = open(fout, 'w')
    fe = open(ferr, 'w')

    if exclusive and single_thread: # requires root
        cmd = 'chrt -f 99 ' + cmd
    if single_thread: # bind to cpu #3 by default
        cmd = 'taskset 1 ' + cmd
    cmd = '/usr/bin/time -p -o _time_ ' + cmd

    global proc
    proc = sp.Popen(shlex.split(cmd), stdin=fi, stdout=fo, stderr=fe, env=os.environ.copy())

    tm = time.time()

    try:
        ru = os.wait4(proc.pid, 0)
    except:
        raise
    finally:
        tm = time.time() - tm
        proc = None
        if fi != sp.PIPE:
            fi.close()
        fo.close()
        fe.close()
        #if ru[1] != 0:
        #   raise Exception('Command "{}" failed with exit code {}'.format(cmd, ru[1])

    ru = list(ru) + [float(tm), [], cmd]
    with open('_time_') as ft:
        for l in ft:
            l = l.strip().split()
            try:
                t = (l[0], float(l[1])) 
                ru[-2].append(t)
            except ValueError:
                pass
    os.remove('_time_')

    return ru
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号