Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 improve time operators performance #7

Merged
merged 14 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added usage of map instead of apply in get_frequencies on class Shift…
…_dates.
  • Loading branch information
mla2001 committed Oct 3, 2024
commit 08211b097b711c474e90a871af6d02a7c84b840e
35 changes: 23 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,33 @@

from vtlengine.API import run

base_path = Path(__file__).parent / 'development' / 'data'
dev_name = 'BOP'
base_path = Path(__file__).parent / 'development' / 'data' / dev_name
input_dp = base_path / 'dataPoints' / 'input'
output_dp = base_path / 'dataPoints' / 'output'
input_ds = base_path / 'dataStructures' / 'input'
ext_routines = base_path / 'externalRoutines'
vds = base_path / 'valueDomains'
vtl = base_path / 'vtl' / 'monthVal.vtl'
vtl = base_path / 'vtl' / f'{dev_name}.vtl'

if __name__ == '__main__':
start = time()
run(
script=vtl,
data_structures=input_ds,
datapoints=input_dp,
value_domains=vds,
output_folder=output_dp,
)
end = time()
print(f"Execution time: {round(end - start, 2)}s")
time_vector = []
num_executions = 3
for i in range(num_executions):
start = time()
run(
script=vtl,
data_structures=input_ds,
datapoints=input_dp,
value_domains=vds,
output_folder=output_dp,
)
end = time()
total_time = round(end - start, 2)
time_vector.append(total_time)
print(f'Execution ({i + 1}/{num_executions}): {total_time}s')
print('-' * 30)
print(f'Average time: {round(sum(time_vector) / num_executions, 2)}s')
print(f'Min time: {min(time_vector)}s')
print(f'Max time: {max(time_vector)}s')
print(f'Total time: {round(sum(time_vector), 2)}s')
2 changes: 1 addition & 1 deletion src/vtlengine/Operators/Time.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def evaluate(cls, operand: Dataset, shift_value: Scalar) -> Dataset:
data_type = result.components[cls.time_id].data_type

if data_type == Date:
freq = cls.find_min_frequency(cls.get_frequencies(result.data[cls.time_id].apply(cls.parse_date)))
freq = cls.find_min_frequency(cls.get_frequencies(result.data[cls.time_id].map(cls.parse_date, na_action='ignore')))
result.data[cls.time_id] = cls.shift_dates(result.data[cls.time_id], shift_value, freq)
elif data_type == Time:
freq = cls.get_frequency_from_time(result.data[cls.time_id].iloc[0])
Expand Down