File: remove-from-bench-json.py

package info (click to toggle)
haskell-futhark 0.25.32-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 18,236 kB
  • sloc: haskell: 100,484; ansic: 12,100; python: 3,440; yacc: 785; sh: 561; javascript: 558; lisp: 399; makefile: 277
file content (35 lines) | stat: -rwxr-xr-x 871 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python
#
# Remove some benchmark from a JSON file produced by futhark-bench's --json
# option.
#
# This is useful if we accidentally added some pointless programs that
# just obscure things.

import json
import sys

remove = sys.argv[1]
files = sys.argv[2:]

removed = False
i = 0
for fp in files:
    with open(fp, "r") as infile:
        try:
            file_json = json.load(infile)
        except Exception as e:
            print("Could not read {}: {}".format(fp, e))
            continue
    for b in file_json.keys():
        if remove in b:
            file_json.pop(b)
            removed = True
    with open(fp, "w") as outfile:
        json.dump(file_json, outfile)
    i += 1
    if i % 100 == 0:
        print("{}/{} files processed...".format(i, len(files)))

if not removed:
    print("Warning: no JSON file contained {}".format(remove))