]>
git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/dev/archery/archery/benchmark/codec.py
1 # Licensed to the Apache Software Foundation (ASF) under one
2 # or more contributor license agreements. See the NOTICE file
3 # distributed with this work for additional information
4 # regarding copyright ownership. The ASF licenses this file
5 # to you under the Apache License, Version 2.0 (the
6 # "License"); you may not use this file except in compliance
7 # with the License. You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied. See the License for the
15 # specific language governing permissions and limitations
21 from ..benchmark
.core
import Benchmark
, BenchmarkSuite
22 from ..benchmark
.runner
import BenchmarkRunner
, StaticBenchmarkRunner
23 from ..benchmark
.compare
import BenchmarkComparator
26 class JsonEncoder(json
.JSONEncoder
):
28 if isinstance(o
, Benchmark
):
29 return BenchmarkCodec
.encode(o
)
31 if isinstance(o
, BenchmarkSuite
):
32 return BenchmarkSuiteCodec
.encode(o
)
34 if isinstance(o
, BenchmarkRunner
):
35 return BenchmarkRunnerCodec
.encode(o
)
37 if isinstance(o
, BenchmarkComparator
):
38 return BenchmarkComparatorCodec
.encode(o
)
40 return json
.JSONEncoder
.default(self
, o
)
49 "less_is_better": b
.less_is_better
,
51 "time_unit": b
.time_unit
,
53 "counters": b
.counters
,
57 def decode(dct
, **kwargs
):
58 return Benchmark(**dct
, **kwargs
)
61 class BenchmarkSuiteCodec
:
66 "benchmarks": [BenchmarkCodec
.encode(b
) for b
in bs
.benchmarks
]
70 def decode(dct
, **kwargs
):
71 benchmarks
= [BenchmarkCodec
.decode(b
)
72 for b
in dct
.pop("benchmarks", [])]
73 return BenchmarkSuite(benchmarks
=benchmarks
, **dct
, **kwargs
)
76 class BenchmarkRunnerCodec
:
79 return {"suites": [BenchmarkSuiteCodec
.encode(s
) for s
in br
.suites
]}
82 def decode(dct
, **kwargs
):
83 suites
= [BenchmarkSuiteCodec
.decode(s
)
84 for s
in dct
.pop("suites", [])]
85 return StaticBenchmarkRunner(suites
=suites
, **dct
, **kwargs
)
88 class BenchmarkComparatorCodec
:
91 comparator
= bc
.formatted
93 suite_name
= bc
.suite_name
95 comparator
["suite"] = suite_name