def measure_mem(x, infilename, outfilename):
    massiffilename = tempfile.mktemp()
    run_exec(Exec(args=(['valgrind', '-q', '--tool=massif', '--pages-as-heap=yes', ('--massif-out-file=' + massiffilename)] + x.args), inp=x.inp, outp=x.outp), infilename, outfilename)
    with open(massiffilename) as f:
        maxmem = 0
        for line in f.readlines():
            match = re.match('^mem_heap_B=([0-9]+)', line)
            if match:
                maxmem = max(maxmem, int(match.group(1)))
    os.remove(massiffilename)
    return maxmem
def measure_mem(x, infilename, outfilename):
    massiffilename = tempfile.mktemp()
    run_exec(Exec(args=(['valgrind', '-q', '--tool=massif', '--pages-as-heap=yes', ('--massif-out-file=' + massiffilename)] + x.args), inp=x.inp, outp=x.outp), infilename, outfilename)
    with open(massiffilename) as f:
        maxmem = 0
        for line in f.readlines():
            match = re.match('^mem_heap_B=([0-9]+)', line)
            if match:
                maxmem = max(maxmem, int(match.group(1)))
    os.remove(massiffilename)
    return maxmem