Skip to content

Commit 299aaf7

Browse files
committed
Benchmark code formatting, more refactoring
1 parent 6ddfa6c commit 299aaf7

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

benchmarks/decoders/benchmark_decoders.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
class DecoderKind:
3232
display_name: str
3333
kind: typing.Type[AbstractDecoder]
34-
default_options: dict = field(default_factory=dict)
34+
default_options: dict[str, str] = field(default_factory=dict)
3535

3636

3737
decoder_registry = {
@@ -66,6 +66,16 @@ def get_test_resource_path(filename: str) -> str:
6666
return str(Path(__file__).parent / f"../../test/resources/{filename}")
6767

6868

69+
def parse_options_code(options_code: str) -> dict[str, str]:
70+
options = {}
71+
for item in options_code.split("+"):
72+
if item.strip() == "":
73+
continue
74+
k, v = item.split("=")
75+
options[k] = v
76+
return options
77+
78+
6979
def main() -> None:
7080
"""Benchmarks the performance of a few video decoders"""
7181

@@ -98,19 +108,17 @@ def main() -> None:
98108
"--decoders",
99109
help=(
100110
"Comma-separated list of decoders to benchmark. "
101-
"Choices are: "
102-
+ ", ".join(decoder_registry.keys())
103-
+ ". "
104-
+ "To specify options, append a ':' and then value pairs seperated by a '+'. "
105-
"For example, torchcodec:num_threads=1+color_conversion_library=filtergraph."
111+
"Choices are: " + ", ".join(decoder_registry.keys()) + ". "
112+
"To specify options, append a ':' and then value pairs seperated by a '+'. "
113+
"For example, torchcodec_core:num_threads=1+color_conversion_library=filtergraph."
106114
),
107115
type=str,
108116
default=(
109117
"decord,decord_batch,"
110-
+ "torchvision,"
111-
+ "torchaudio,"
112-
+ "torchcodec_core,torchcodec_core:num_threads=1,torchcodec_core_batch,torchcodec_core_nonbatch,"
113-
+ "torchcodec_public"
118+
"torchvision,"
119+
"torchaudio,"
120+
"torchcodec_core,torchcodec_core:num_threads=1,torchcodec_core_batch,torchcodec_core_nonbatch,"
121+
"torchcodec_public"
114122
),
115123
)
116124
parser.add_argument(
@@ -135,27 +143,19 @@ def main() -> None:
135143
decoders_to_run = {}
136144
for decoder in specified_decoders:
137145
if ":" in decoder:
138-
decoder_name, _, options = decoder.partition(":")
139-
assert decoder_name in decoder_registry
140-
141-
kwargs_dict = {}
142-
for item in options.split("+"):
143-
if item.strip() == "":
144-
continue
145-
k, v = item.split("=")
146-
kwargs_dict[k] = v
147-
148-
display_name = decoder_registry[decoder_name].display_name
149-
kind = decoder_registry[decoder_name].kind
150-
decoders_to_run[display_name + options] = kind(**kwargs_dict)
146+
decoder, _, options_code = decoder.partition(":")
147+
assert decoder in decoder_registry
148+
display = decoder_registry[decoder].display_name + options_code
149+
options = parse_options_code(options_code)
151150
elif decoder in decoder_registry:
152-
display_name = decoder_registry[decoder].display_name
153-
kind = decoder_registry[decoder].kind
154-
default_options = decoder_registry[decoder].default_options
155-
decoders_to_run[display_name] = kind(**default_options)
151+
display = decoder_registry[decoder].display_name
152+
options = decoder_registry[decoder].default_options
156153
else:
157154
raise ValueError(f"Unknown decoder: {decoder}")
158155

156+
kind = decoder_registry[decoder].kind
157+
decoders_to_run[display] = kind(**options)
158+
159159
video_paths = args.bm_video_paths.split(",")
160160
if args.bm_video_dir:
161161
video_paths = []

0 commit comments

Comments
 (0)