Skip to content

Instantly share code, notes, and snippets.

@TheVishnuKumar
Last active November 14, 2018 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheVishnuKumar/3085c933c008dddfb9f7dd172bf1486a to your computer and use it in GitHub Desktop.
Save TheVishnuKumar/3085c933c008dddfb9f7dd172bf1486a to your computer and use it in GitHub Desktop.
/*
Speed Test - Which One is Fast to Compare String from ==, equals and equalsIgnoreCase
Author: 0to1Code.Com
*/
public class ApexSpeedExperiment_3{
//Experiment 1 : Using ==
public static void runExperiment1(){
system.debug('CPU Limit Consumption Start: '+Limits.getCPUtime());
for(Integer i=0; i<50000 ;i++){
if( 'Test'=='Test' ){}
}
system.debug('CPU Limit Consumption End: '+Limits.getCPUtime());
}
//Experiment 2 : Using equals method
public static void runExperiment2(){
system.debug('CPU Limit Consumption Start: '+Limits.getCPUtime());
for(Integer i=0; i<50000 ;i++){
if( 'Test'.equals('Test') ){}
}
system.debug('CPU Limit Consumption End: '+Limits.getCPUtime());
}
//Experiment 3 : Using equalsIgnoreCase method
public static void runExperiment3(){
system.debug('CPU Limit Consumption Start: '+Limits.getCPUtime());
for(Integer i=0; i<50000 ;i++){
if( 'Test'.equalsIgnoreCase('Test') ){}
}
system.debug('CPU Limit Consumption End: '+Limits.getCPUtime());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment