Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
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