|
| 1 | +# Write the benchmarking functions here. |
| 2 | +# See "Writing benchmarks" in the asv docs for more information. |
| 3 | + |
| 4 | +import subprocess |
| 5 | +import os |
| 6 | +from pathlib import Path |
| 7 | +import numpy as np |
| 8 | +import tempfile |
| 9 | + |
| 10 | +base_path = Path("~/regression/dgl/") |
| 11 | + |
| 12 | +class PartitionBenchmark: |
| 13 | + |
| 14 | + params = [['pytorch'], ['livejournal']] |
| 15 | + param_names = ['backend', 'dataset'] |
| 16 | + timeout = 600 |
| 17 | + |
| 18 | + def __init__(self): |
| 19 | + self.std_log = {} |
| 20 | + |
| 21 | + def setup(self, backend, dataset): |
| 22 | + key_name = "{}_{}".format(backend, dataset) |
| 23 | + if key_name in self.std_log: |
| 24 | + return |
| 25 | + bench_path = base_path / "tests/regression/benchmarks/partition.py" |
| 26 | + bashCommand = "/opt/conda/envs/{}-ci/bin/python {} --dataset {}".format( |
| 27 | + backend, bench_path.expanduser(), dataset) |
| 28 | + process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE,env=dict(os.environ, DGLBACKEND=backend)) |
| 29 | + output, error = process.communicate() |
| 30 | + print(str(error)) |
| 31 | + self.std_log[key_name] = str(output) |
| 32 | + |
| 33 | + |
| 34 | + def track_partition_time(self, backend, dataset): |
| 35 | + key_name = "{}_{}".format(backend, dataset) |
| 36 | + lines = self.std_log[key_name].split("\\n") |
| 37 | + |
| 38 | + time_list = [] |
| 39 | + for line in lines: |
| 40 | + # print(line) |
| 41 | + if 'Time:' in line: |
| 42 | + time_str = line.strip().split(' ')[1] |
| 43 | + time = float(time_str) |
| 44 | + time_list.append(time) |
| 45 | + return np.array(time_list).mean() |
| 46 | + |
| 47 | + |
| 48 | +PartitionBenchmark.track_partition_time.unit = 's' |
| 49 | + |
0 commit comments