Engee documentation
Notebook

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.

image_4.png

image_5.png

Function for starting the model

In [ ]:
Pkg.add(["TickTock"])
In [ ]:
# Подключение вспомогательной функции запуска модели.
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
Out[0]:
run_model (generic function with 1 method)

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:

  1. 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.
  2. TickTock works with high precision timing, which provides reliable code execution time data even for very fast operations.
  3. 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.
In [ ]:
using TickTock
In [ ]:
tick()
run_model("sin_Sample") # Запуск модели.
Ts = tok()
Out[0]:
7.545560097
In [ ]:
tick()
run_model("sin_Frame") # Запуск модели.
Tf = tok()
Out[0]:
7.903039812
In [ ]:
println("Time sin_Sample: $(Ts)")
println("Time sin_Frame: $(Tf)")
println("Time difference: $(abs(Ts-Tf))")
Time sin_Sample: 7.545560097
Time sin_Frame: 7.903039812
Time difference: 0.3574797150000002

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.

In [ ]:
Ss = collect(Ss);
Sf = collect(Sf);
Sf = reduce(vcat, Sf.value)

println("Size sin_Sample: $(size(Ss))")
println("Size sin_Frame: $(size(Ss))")
Size sin_Sample: (10001, 2)
Size sin_Frame: (10001, 2)

As we can see, the signal dimensions are equal.

In [ ]:
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))")
Out[0]:

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.

Blocks used in example