Summary - getAll() is >10x faster, but SOQL is still fast
Based on my testing scenario, using custom settings instance methods offer ~40x performance improvement, in addition to the advantages of not consuming a query limit. However, both are still pretty fast so this sort of tuning probably isn't the best focus of optimization. This increase is must less pronounced for the first access (assuming the records are only put in memcache as accessed).
Test Scenario
Testing performed with a custom setting with a checkbox, text(2), and text(3) field with 250 records in a dev sandbox with debugs logs enabled.
SOQL Test
List<CustomSetting__c> settings;
Long startTime = DateTime.now().getTime();
for(Integer i = 0; i < 100; i++) {
settings = [
SELECT Id, Checkbox__c, Text2__c, Text3__c, Name, CreatedDate,
CreatedById, SystemModStamp, LastModifiedById, LastModifiedDate
FROM CustomSetting__c];
}
Long stopTime = DateTime.now().getTime();
Long totalMs = stopTime - startTime;
system.debug('==>totalMS: ' + totalMs);
Custom Settings getAll() Method
Long startTime = DateTime.now().getTime();
for(Integer i = 0; i < 100; i++) {
CustomSetting__c.getAll();
}
Long stopTime = DateTime.now().getTime();
Long totalMs = stopTime - startTime;
system.debug('==>totalMS: ' + totalMs);
Results
SOQL
Completion times were 887ms, 1055ms, 1014ms, 965ms, and 925ms for an average of 9.692ms/iteration.
Custom Settings getAll() Method
Completion times were 218ms, 17ms, 18ms, 45ms, and 18ms for an average of 0.632/iteration including all results. Excluding the initial result outlier an average of 0.245ms/iteration.
FOR UPDATE
(without which I'm risking the "Unable to lock row" errors). No idea about performance considerations...