Guest User

Untitled

a guest
Nov 14th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. /*
  2. Speed Test - Which One is Fast to Compare String from ==, equals and equalsIgnoreCase
  3. Author: 0to1Code.Com
  4. */
  5. public class ApexSpeedExperiment_3{
  6.  
  7. //Experiment 1 : Using ==
  8. public static void runExperiment1(){
  9.  
  10. system.debug('CPU Limit Consumption Start: '+Limits.getCPUtime());
  11.  
  12. for(Integer i=0; i<50000 ;i++){
  13. if( 'Test'=='Test' ){}
  14. }
  15.  
  16. system.debug('CPU Limit Consumption End: '+Limits.getCPUtime());
  17. }
  18.  
  19. //Experiment 2 : Using equals method
  20. public static void runExperiment2(){
  21.  
  22. system.debug('CPU Limit Consumption Start: '+Limits.getCPUtime());
  23.  
  24. for(Integer i=0; i<50000 ;i++){
  25. if( 'Test'.equals('Test') ){}
  26. }
  27.  
  28. system.debug('CPU Limit Consumption End: '+Limits.getCPUtime());
  29. }
  30.  
  31. //Experiment 3 : Using equalsIgnoreCase method
  32. public static void runExperiment3(){
  33.  
  34. system.debug('CPU Limit Consumption Start: '+Limits.getCPUtime());
  35.  
  36. for(Integer i=0; i<50000 ;i++){
  37. if( 'Test'.equalsIgnoreCase('Test') ){}
  38. }
  39.  
  40. system.debug('CPU Limit Consumption End: '+Limits.getCPUtime());
  41. }
  42. }
Add Comment
Please, Sign In to add comment