Created
June 26, 2017 22:33
-
-
Save kurunve/24322de8df1b85b7a45c956c52ab0016 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usecase -- 1000 accounts with different ids | |
// Procedure of testing. Basically a define [1000/a] records in first set, and b define [1000/b] records in second set | |
public static void doMagic(Integer a, Integer b) { | |
Map<Id, Account> accs = new Map<Id, Account>([SELECT Id FROM Account]); | |
system.debug(accs.size()); | |
Set<Id> account_ids = accs.keySet(); | |
Set<Id> set1 = new Set<id>(); | |
Set<Id> set2 = new Set<Id>(); | |
Set<Id> set1_a = new Set<id>(); | |
Set<Id> set2_a = new Set<Id>(); | |
Integer counter = 0; | |
for(Id i : account_ids) { | |
if (Math.mod(counter, a) == 0) { | |
set1.add(i); | |
set1_a.add(i); | |
} | |
if (Math.mod(counter , b) == 0) { | |
set2.add(i); | |
set2_a.add(i); | |
} | |
counter++; | |
} | |
DateTime start1 = DateTime.now(); | |
Set<Id> p1 = set2; | |
p1.removeAll(set1); | |
DateTime end1 = DateTime.now(); | |
System.debug('WAY1: ' + (end1.getTime() - start1.getTime())); | |
DateTime start2 = DateTime.now(); | |
Set<Id> result = new Set<Id>(); | |
for (Id x : set2_a) { | |
if ( !set1_a.contains(x) ) { | |
result.add(x); | |
} | |
} | |
DateTime end2 = DateTime.now(); | |
System.debug('WAY2: ' + (end2.getTime() - start2.getTime())); | |
} | |
//RUNS | |
1. Scenario 1, a = 2, b = 3 | |
WAY1: 1 | |
WAY2: 32 | |
2. Scenario 2, a = 101, b = 3 | |
WAY1: 0 | |
WAY2: 35 | |
3. Scenario 3, a = 2, b = 301, | |
WAY1: 2 | |
WAY2: 2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment