Engee documentation
Notebook

MATLAB and Engee speed comparison

In this example, we will compare the execution speed of a simple script implemented in MATLAB and in Engee. To do this, we will need two libraries MATLAB to connect the MATLAB computing core and TickTock to measure the time required 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 specifying a sine wave and several 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 the cycles. To do this, we will use all available acceleration features in Engee – we 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

Obviously, the vector repeat function in MATLAB performs significantly worse than a similar function in Engee.

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

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

In this example, we can see that Engee handles data display much faster.

Also, let's display the results of the generated data as an image, and also run the entire script described above in order to get a clearer picture of the final speed difference.

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 experiment described above, we can conclude that Julia performs calculations much faster than MATLAB.