Created
May 2, 2012 01:24
-
-
Save mdakin/2572868 to your computer and use it in GitHub Desktop.
Perforance test of basic set operations in dart
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
void runTests(Set<String> se, List<String> data) { | |
Stopwatch w = new Stopwatch(); | |
w.start(); | |
for (String s in data) { | |
se.add(s); | |
} | |
print("Add: ${w.elapsedInMs()} ms."); | |
num i = 0; | |
w.reset(); | |
for (String s in data) { | |
if (se.contains(s)) { | |
i+= s.length; | |
} | |
} | |
print("Contains: ${w.elapsedInMs()} ms."); | |
w.reset(); | |
for (String s in se) { | |
i+= s.length; | |
} | |
print("Iterate: ${w.elapsedInMs()} ms."); | |
w.reset(); | |
for (String s in data) { | |
se.remove(s); | |
} | |
print("Remove: ${w.elapsedInMs()} ms."); | |
w.reset(); | |
data.sort(compare(String a, String b) { | |
return a.compareTo(b); | |
}); | |
print("Sort list: ${w.elapsedInMs()} ms."); | |
} | |
void main() { | |
List<String> data = new List<String>(); | |
for (int i=0; i<500000; i++) { | |
String s = "${Math.random()}"; | |
data.add(s); | |
} | |
runTests(new HashSet<String>(), data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment