sometimes doing all the code right by self and when posting on online compilers it shows TLE or MLE . Is there a way so that i can limit the resource to visual studio so that it imitates like leetcode or hackkerank IDE…
couldnt find any solution publicly available to google search
2
Answers
I’ll clear up something really quick: Visual Studio Code is not an IDE, it’s a text editor. Therefore it’s not up to it to decide the compilation and linking process. It can however integrate into shell to run shell commands to build your project.
On Linux you can use the
time
utility to verify that your running time is reasonable. You can run it from a terminal like that.As for windows, I don’t know any good built-in alternatives, except that I know that in PowerShell there’s a
Measure-Command
cmdlet. If your VSCode terminal shell is PowerShell you can type the following:To check memory usage of your program I can recommend using
valgrind
. This tool is useful for detecting many kinds of memory issues. You can learn more about it here.To make this easier you can integrate these commands into your build tasks. You can learn more about those here
Note that these tools will simply display information about the usage of time and memory in your program, they won’t error-out on large limits. So you’ll have to manually check the output of these commands if you want to verify your program’s efficiency.
You could use
std::chrono
to implement time based limits at runtime.Or at least emit a "pass"/"fail" condition at runtime depending on whether the limit was exceeded or not.