SHOW:
|
|
- or go back to the newest paste.
1 | import 'dart:math'; | |
2 | import 'dart:js'; | |
3 | ||
4 | void main() { | |
5 | List<String> stringList1 = new List<String>(); | |
6 | List<String> stringList2; | |
7 | ||
8 | Random rnd = new Random(); | |
9 | for(int i = 0; i < 100000; ++i) { | |
10 | stringList1.add(rnd.nextInt(1000000000).toString()); | |
11 | } | |
12 | stringList2 = new List<String>.from(stringList1); | |
13 | ||
14 | // First test - uses JS implementation of Quicksort | |
15 | Stopwatch sw = new Stopwatch()..start(); | |
16 | stringList1.sort((String a, String b) => a.compareTo(b)); | |
17 | sw.stop(); | |
18 | print("Quicksort sorting is done in: ${sw.elapsed.inMilliseconds}"); | |
19 | ||
20 | // Second test - let's make sure that Array.prototype.sort() is called | |
21 | sw | |
22 | ..reset() | |
23 | ..start(); | |
24 | JsArray arr = new JsArray.from(stringList2); | |
25 | arr.sort((String a, String b){ a.compareTo(b); }); | |
26 | List<String> sortedList = arr.toList(); | |
27 | sw.stop(); | |
28 | print("JS sorting is done in: ${sw.elapsed.inMilliseconds}"); | |
29 | } | |
30 | ||
31 | /* | |
32 | - | Results: |
32 | + | Dart 1.7.2 - "unchecked" mode |
33 | Results (3 runs, with Quicksort/Array.sort format): | |
34 | Chrome 38: 89/155, 144/156, 100/168 | |
35 | FX 33: 225/354, 228/349, 225/369 | |
36 | IE 11: 1028/1435, 1028/1415, 1111/1422 | |
37 | ||
38 | Interesting: Array.prototype.sort seems to be slower for this case | |
39 | */ |