File: gfapy-plot-preparedata.py

package info (click to toggle)
gfapy 1.0.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,932 kB
  • sloc: python: 11,549; sh: 167; makefile: 66
file content (62 lines) | stat: -rwxr-xr-x 2,050 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
"""
Prepare the output of the convert benchmark script for the R plotting script.
"""

import argparse
import os
import sys
import re

op = argparse.ArgumentParser(description=__doc__)
op.add_argument('--version', action='version', version='%(prog)s 1.0')
op.add_argument("--mult", "-m", action="store_true",
    help="set if variable n of edges/segment")
op.add_argument("inputfile")
opts = op.parse_args()

if not os.path.exists(opts.inputfile):
  sys.stderr.write("Input file not found: {}\n".format(opts.inputfile))
  exit(1)

with open(opts.inputfile) as inputfile:
  header = True
  if opts.mult:
    outdata = ["mult", "time", "space", "time_per_line", "space_per_line"]
  else:
    outdata = ["lines", "time", "space", "time_per_line", "space_per_line"]
  print("\t".join(outdata))
  for line in inputfile:
    if line[:3] == "###":
      header = False
    elif not header:
      data = line.rstrip("\n\r").split("\t")
      n_segments = data[2]
      multiplier = data[3]
      n_lines = int(int(n_segments) * (1+float(multiplier)))
      elapsed = data[5]
      elapsed_match = re.compile(r'\s+(\d+):(\d+\.\d+)').match(elapsed)
      if elapsed_match:
        minutes = int(elapsed_match.groups()[0])
        seconds = float(elapsed_match.groups()[1])
        seconds += minutes * 60
      else:
        elapsed_match = re.compile(r'\s+(\d+):(\d+):(\d+)').match(elapsed)
        if elapsed_match:
          hours = int(elapsed_match.groups()[0])
          minutes = int(elapsed_match.groups()[1])
          seconds = int(elapsed_match.groups()[2])
          minutes += hours * 60
          seconds += minutes * 60
        else:
          continue
      memory = data[6]
      memory = int(re.compile(r'(\d+) kB').match(memory).groups()[0])
      megabytes = memory / 1024
      if opts.mult:
        outdata = [str(multiplier)]
      else:
        outdata = [str(n_lines)]
      outdata += [str(seconds),str(megabytes),
                  str(seconds/n_lines), str(megabytes/n_lines)]
      print("\t".join(outdata))