Skip to content

Commit 92304cf

Browse files
committed
Adds format option for read command
1 parent d7d7d50 commit 92304cf

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

amazon/ionbenchmark/ion_benchmark_cli.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,21 @@ def reset_for_each_execution(each_option):
344344
return api, format_option
345345

346346

347+
def convert_file_to_desired_format(f, file):
348+
if f == Format.ION_BINARY.value:
349+
cf = open("converted_file", "wb")
350+
with open(file, "br") as fp:
351+
ion.dump(ion.load(fp, single_value=False), cf, binary=True)
352+
return cf.name
353+
elif f == Format.ION_TEXT.value:
354+
cf = open("converted_file", "wb")
355+
with open(file, "br") as fp:
356+
ion.dump(ion.load(fp, single_value=False), cf, binary=False)
357+
return cf.name
358+
else:
359+
raise Exception('Failed to convert file due to unknown format.')
360+
361+
347362
def ion_python_benchmark_cli(arguments):
348363
if arguments['--version'] or arguments['-v']:
349364
print(TOOL_VERSION)
@@ -372,6 +387,7 @@ def ion_python_benchmark_cli(arguments):
372387
for each_option in option_configuration_combination:
373388
# reset
374389
api, format_option = reset_for_each_execution(each_option)
390+
converted_file = convert_file_to_desired_format(format_option, file)
375391

376392
if not api or api == API.SIMPLE_ION.value:
377393
read_micro_benchmark_function = read_micro_benchmark_simpleion
@@ -381,12 +397,10 @@ def ion_python_benchmark_cli(arguments):
381397
raise Exception(f'Invalid API option {api}.')
382398

383399
file_size, result_with_gc, conversion_time, read_memory_usage_peak = \
384-
read_micro_benchmark_and_profiling(table, read_micro_benchmark_function, iterations, warmups, file,
385-
c_extension, iterator, each_option)
400+
read_micro_benchmark_and_profiling(table, read_micro_benchmark_function, iterations, warmups,
401+
converted_file, c_extension, iterator, each_option)
386402

387403
print(tabulate(table, tablefmt='fancy_grid'))
388-
389-
390404
elif arguments['write']:
391405
# initialize benchmark report table
392406
table = identify_report_table('write')

0 commit comments

Comments
 (0)