import re


def parse(lines):
    """Takes iterable lines of bench output, returns {bench:{config:time}}."""
    
    benches = {}
    current_bench = None
    
    for line in lines:
        #see if this line starts a new bench
        new_bench = re.search('running bench \[\d+ \d+\] (.{28})', line)
        if new_bench:
            current_bench = new_bench.group(1)
        
        #add configs on this line to the current bench
        if current_bench:
            for new_config in re.finditer('  (.{4}): msecs = (\d+\.\d+)', line):
                current_config = new_config.group(1)
                current_time = float(new_config.group(2))
                if current_bench in benches:
                    benches[current_bench][current_config] = current_time
                else:
                    benches[current_bench] = {current_config : current_time}
    
    return benches