import csv


def _read_benchmark_numbers(benchmark_filepath):
  """Reads benchmark numbers from file.

  Args:
    benchmark_filepath: string, file path to benchmark result.

  Returns:
    A list of benchmark names and a list of corresponding performance
      number (in ns).
  """
  with open(benchmark_filepath) as csvfile:
    reader = csv.reader(csvfile)
    benchmark_numbers = [row for row in reader]
    # Get rid of information about CPU at the beginning of benchmark file.
    # Use the length of regular benchmark entry as a ruler.
    benchmark_entry_length = len(benchmark_numbers[-1])
    benchmark_numbers = [
        row for row in benchmark_numbers if len(row) == benchmark_entry_length
    ]
    # Pop up header
    benchmark_numbers.pop(0)
    names = [row[0] for row in benchmark_numbers]
    perf_numbers = [float(row[2]) for row in benchmark_numbers]
    cpu_numbers = [float(row[3]) for row in benchmark_numbers]
    return names, perf_numbers, cpu_numbers