function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ambitiambiti 

How to get the time spent running a sript?

I'm new here,please help me. 

While doing a  math operation,like 1+1 million times,how can I get the  time spent running this code? In php there's a microtime() function to do this, is there a samilar funciton in Apex?

Best Answer chosen by Admin (Salesforce Developers) 
ascuccimarraascuccimarra

I don't know if this is what you were looking for.

 

Long start = System.now().getTime();
Integer i = 0;
while (i < 100000){
    i++;
}
Long miliseconds = System.now().getTime() - start;
System.debug(miliseconds);

 

 

That'd show the number of miliseconds spent in the proccess.

Hope this helps.

All Answers

ascuccimarraascuccimarra

I don't know if this is what you were looking for.

 

Long start = System.now().getTime();
Integer i = 0;
while (i < 100000){
    i++;
}
Long miliseconds = System.now().getTime() - start;
System.debug(miliseconds);

 

 

That'd show the number of miliseconds spent in the proccess.

Hope this helps.

This was selected as the best answer
ambitiambiti

Thanks for your attention!