Estimation of model execution time in Engee¶
In this example, we will look at the possibilities of comparing models by speed.
For demonstration we will take two identical models with identical parameters. There is one difference: in the first case we will use pipeline calculations, and in the second case - vector calculations.
The models themselves are shown in the figure below.
Function for starting the model¶
Pkg.add(["TickTock"])
# Подключение вспомогательной функции запуска модели.
function run_model( name_model)
Path = (@__DIR__) * "/" * name_model * ".engee"
if name_model in [m.name for m in engee.get_all_models()] # Проверка условия загрузки модели в ядро
model = engee.open( name_model ) # Открыть модель
model_output = engee.run( model, verbose=true ); # Запустить модель
else
model = engee.load( Path, force=true ) # Загрузить модель
model_output = engee.run( model, verbose=true ); # Запустить модель
engee.close( name_model, force=true ); # Закрыть модель
end
sleep(5)
return model_output
end
Speed comparison¶
Now let's move on to the speed comparison. Let's use the TickTock library and the tick() and tok() functions.
tick() - records the current moment of time. Usually used to start time measurement. tok() - calculates and outputs the time elapsed since the last tick() call.
Features and benefits of using TickTock:
- The tick() and tok() functions provide a simple and intuitive way to measure time without having to manually calculate the difference between the start and end times.
- TickTock works with high precision timing, which provides reliable code execution time data even for very fast operations.
- The measurement result is output in an easy-to-understand format (seconds, milliseconds), and the output data format is standard Float64, which allows you to easily convert these values into minutes or hours.
using TickTock
tick()
run_model("sin_Sample") # Запуск модели.
Ts = tok()
tick()
run_model("sin_Frame") # Запуск модели.
Tf = tok()
println("Time sin_Sample: $(Ts)")
println("Time sin_Frame: $(Tf)")
println("Time difference: $(abs(Ts-Tf))")
As we can see from the difference calculation, the execution time differs insignificantly. Let us also compare the simulation results to make sure that the models are identical.
Ss = collect(Ss);
Sf = collect(Sf);
Sf = reduce(vcat, Sf.value)
println("Size sin_Sample: $(size(Ss))")
println("Size sin_Frame: $(size(Ss))")
As we can see, the signal dimensions are equal.
gr()
error = abs.(Sf[1:100]-Ss.value[1:100]);
plot(Ss.value[1:100], label="sin_Sample")
plot!(Sf[1:100], label="sin_Frame")
plot!(error, label="difference")
title!("sum_error: $(sum(error))")
The signals are identical both by dimensions and by the results of comparison of the signals themselves.
Conclusion¶
In this example, we have seen how the TickTock library can be used to compare the speed of different models. This tool is useful for analysing the performance of your models and assessing whether they need to be optimised.