How can I make the execution speed consistent while I am testing the speed of the programs?

4 views (last 30 days)
I am working on cryptography and testing the execution speed. but when i test the execution speed varies with the same input argument. I was considering the variation comes due to the shared resource by the application that run in the computer. so what shall i do? shall i install MATLAB in virtual box with dedicated resource, if it is possible? Anyone please help me?

Accepted Answer

Nikhilesh
Nikhilesh on 24 Jan 2023
The variation in execution speed that you are experiencing is likely due to the fact that your computer is running other applications and processes that are sharing resources with MATLAB. This can lead to unpredictable performance, as the performance of your code may be affected by the current usage of the system resources by other applications.
One way to address this issue is to run MATLAB in a virtual machine (VM) using virtualization software such as VirtualBox. By running MATLAB in a VM, you can dedicate specific resources (e.g. CPU, RAM) to the VM and minimize the impact of other applications on the performance of your code. Additionally, running MATLAB in a VM can also help to isolate your development environment from the host system, which can be useful for testing and deployment.
  4 Comments
Nikhilesh
Nikhilesh on 24 Jan 2023
Please let me know any specific issues you are facing while installing MATLAB in Virtual Environment.

Sign in to comment.

More Answers (2)

Walter Roberson
Walter Roberson on 24 Jan 2023
Edited: Walter Roberson on 24 Jan 2023
I am not convinced that virtual machines will be allocated dedicated resources that will not be affected by other activities.
If you are using Windows then:
  • safe mode (you might need to use safe mode + internet)
  • disable all system services that are not absolutely necessary
  • lock the process against particular cores

Yair Altman
Yair Altman on 5 Feb 2023
I can certainly understand the desire to use a sandboxed environment that would enable you to optimize the performance of your program without external distractions (for example, background anti-virus checks, OS updates, browser page refreshes etc.). These indeed affect the CPU and memory and therefore your program's executing-time variabiity. As mentioned in the other answers here, there are ways to reduce such distractions to a minimum.
But in addition, note that in real life your program will likely encounter exactly those distractions that you are trying to avoid here. Therefore, optimizing your code for the optimal case (minimal distractions) may possibly make the code sub-optimal for the common case (typical distractions). In most likelihood, you'd rather optimize your code for the typical use-case, not a hypothetical unrealistic optimal use-case.
I'm not saying that sandboxing the application during performance-tuning doesn't have a place, I'm just saying that you should be aware that it has a downside.
One way to work-aroud this limitation is to run the same code using the same inputs multiple times in a loop, and then using the average timing of all these runs. In fact, this is what the builtin timeit funcion does. If you run your code enough times, the effect of spurious distractions from external processes will be minimized, and you'd get a more realistic picture of what your end-user will see. By optimizing the code to make this average run-time faster, you're more likely to get the same effect for end users (some say that it's better to reduce the maximal run-time rather than the average or median, but that's a separate discussion outside of the scope here).

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!