Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:math';
- import 'dart:js';
- void main() {
- List<String> stringList1 = new List<String>();
- List<String> stringList2;
- Random rnd = new Random();
- for(int i = 0; i < 100000; ++i) {
- stringList1.add(rnd.nextInt(1000000000).toString());
- }
- stringList2 = new List<String>.from(stringList1);
- // First test - uses JS implementation of Quicksort
- Stopwatch sw = new Stopwatch()..start();
- stringList1.sort((String a, String b) => a.compareTo(b));
- sw.stop();
- print("Quicksort sorting is done in: ${sw.elapsed.inMilliseconds}");
- // Second test - let's make sure that Array.prototype.sort() is called
- sw
- ..reset()
- ..start();
- JsArray arr = new JsArray.from(stringList2);
- arr.sort((String a, String b){ a.compareTo(b); });
- List<String> sortedList = arr.toList();
- sw.stop();
- print("JS sorting is done in: ${sw.elapsed.inMilliseconds}");
- }
- /*
- Results:
- Chrome 38: 89/155, 144/156, 100/168
- FX 33: 225/354, 228/349, 225/369
- IE 11: 1028/1435, 1028/1415, 1111/1422
- Interesting: Array.prototype.sort seems to be slower for this case
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement