Engee documentation
Notebook

MATLAB and Engee speed comparison

In this example we will compare the speed of execution of a simple script implemented in MATLAB and in Engee. For this purpose we need two libraries MATLAB to connect MATLAB computational kernel and TickTock to measure the time consumption when executing scripts in Engee.

In [ ]:
Pkg.add(["TickTock"])
In [ ]:
Pkg.add("TickTock")
   Resolving package versions...
  No Changes to `~/.project/Project.toml`
  No Changes to `~/.project/Manifest.toml`
In [ ]:
using MATLAB
using TickTock

Now let's compare the speed of assignment and simple calculations by setting a sine wave and a few auxiliary constants.

In [ ]:
mat"""
tic
N = 100;        	
x = (1:N)/N;      	
y = sin(8*pi*x);	
toc
"""

tick()
N = 100;
x = (1:N)/N;
y = sin.(8π.*x);
tock()
>> >> >> >> >> >> >> Elapsed time is 0.004045 seconds.
[ Info:  started timer at: 2024-08-09T12:05:03.563
[ Info:          0.001664594s: 1 millisecond

As we can see, Julia copes with this task many times faster than MATLAB.

Now let's compare the speed of cycles. To do this, let's use all the available acceleration capabilities in Engee - let's use a macro.

In [ ]:
mat"""
tic
I = repmat(y,100,1);
toc
"""

tick()
I = repeat(y, 100, 1)
tock()
>> >> >> >> >> Elapsed time is 0.001147 seconds.
[ Info:  started timer at: 2024-08-09T12:05:03.973
[ Info:          0.000504059s: empty period

It is obvious that the vector repeat function in MATLAB is much worse than the similar function in Engee.

The next aspect we will compare is the graphical display. Here we should consider that there is no mapping for MATLAB in Engee, but the functions themselves inside the kernel can be performed.

In [ ]:
mat"""
tic
pcolor(I);             
colormap(bone);      	
toc
"""

tick()
heatmap(hcat(I...), c=:bone)
tock()
>> >> >> >> >> >> Elapsed time is 0.397273 seconds.
[ Info:  started timer at: 2024-08-09T12:05:04.663
[ Info:          0.005644742s: 5 milliseconds

On this example we can see that Engee is much faster with data display as well.

Let's also display the results of the generated data in the form of an image, and run the entire script described above to get a better idea of the final difference in speed.

In [ ]:
heatmap(hcat(I...), c=:bone)
Out[0]:
In [ ]:
mat"""
tic
N = 100;        	
x = (1:N)/N;      	
y = sin(8*pi*x);		
I = repmat(y,100,1);
pcolor(I);              
colormap(bone);      	
toc
"""

tick()
N = 100;
x = (1:N)/N;
y = sin.(8π.*x);
I = repeat(y, 100, 1)
heatmap(hcat(I...)', c=:bone)
tock()
>> >> >> >> >> >> >> >> >> >> Elapsed time is 0.256024 seconds.
[ Info:  started timer at: 2024-08-09T12:05:05.763
[ Info:          0.004944659s: 4 milliseconds

Conclusion

Based on the above experiment, we can conclude that Julia performs calculations much faster than MATLAB.