OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 library kernel.treeshaker_bench; | 4 library kernel.treeshaker_bench; |
5 | 5 |
6 import 'dart:io'; | 6 import 'dart:io'; |
7 | 7 |
8 import 'package:args/args.dart'; | 8 import 'package:args/args.dart'; |
9 import 'package:kernel/class_hierarchy.dart'; | 9 import 'package:kernel/class_hierarchy.dart'; |
10 import 'package:kernel/core_types.dart'; | 10 import 'package:kernel/core_types.dart'; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 return options['basic'] | 51 return options['basic'] |
52 ? new BasicClassHierarchy(program) | 52 ? new BasicClassHierarchy(program) |
53 : new ClassHierarchy(program); | 53 : new ClassHierarchy(program); |
54 } | 54 } |
55 | 55 |
56 CoreTypes coreTypes = new CoreTypes(program); | 56 CoreTypes coreTypes = new CoreTypes(program); |
57 | 57 |
58 var watch = new Stopwatch()..start(); | 58 var watch = new Stopwatch()..start(); |
59 ClassHierarchy sharedClassHierarchy = buildClassHierarchy(); | 59 ClassHierarchy sharedClassHierarchy = buildClassHierarchy(); |
60 int coldHierarchyTime = watch.elapsedMicroseconds; | 60 int coldHierarchyTime = watch.elapsedMicroseconds; |
61 var shaker = new TreeShaker(program, | 61 var shaker = new TreeShaker(coreTypes, program, |
62 hierarchy: sharedClassHierarchy, | 62 hierarchy: sharedClassHierarchy, strongMode: strongMode); |
63 coreTypes: coreTypes, | |
64 strongMode: strongMode); | |
65 if (options['diagnose']) { | 63 if (options['diagnose']) { |
66 print(shaker.getDiagnosticString()); | 64 print(shaker.getDiagnosticString()); |
67 } | 65 } |
68 shaker = null; | 66 shaker = null; |
69 int coldTreeShakingTime = watch.elapsedMicroseconds; | 67 int coldTreeShakingTime = watch.elapsedMicroseconds; |
70 | 68 |
71 ClassHierarchy getClassHierarchy() { | 69 ClassHierarchy getClassHierarchy() { |
72 return options['from-scratch'] | 70 return options['from-scratch'] |
73 ? buildClassHierarchy() | 71 ? buildClassHierarchy() |
74 : sharedClassHierarchy; | 72 : sharedClassHierarchy; |
75 } | 73 } |
76 | 74 |
77 const int numberOfTrials = 50; | 75 const int numberOfTrials = 50; |
78 int hotHierarchyTime = 0; | 76 int hotHierarchyTime = 0; |
79 int hotTreeShakingTime = 0; | 77 int hotTreeShakingTime = 0; |
80 watch.reset(); | 78 watch.reset(); |
81 for (int i = 0; i < numberOfTrials; i++) { | 79 for (int i = 0; i < numberOfTrials; i++) { |
82 watch.reset(); | 80 watch.reset(); |
83 var hierarchy = getClassHierarchy(); | 81 var hierarchy = getClassHierarchy(); |
84 hotHierarchyTime += watch.elapsedMicroseconds; | 82 hotHierarchyTime += watch.elapsedMicroseconds; |
85 new TreeShaker(program, | 83 new TreeShaker(coreTypes, program, |
86 hierarchy: hierarchy, coreTypes: coreTypes, strongMode: strongMode); | 84 hierarchy: hierarchy, strongMode: strongMode); |
87 hotTreeShakingTime += watch.elapsedMicroseconds; | 85 hotTreeShakingTime += watch.elapsedMicroseconds; |
88 } | 86 } |
89 hotHierarchyTime ~/= numberOfTrials; | 87 hotHierarchyTime ~/= numberOfTrials; |
90 hotTreeShakingTime ~/= numberOfTrials; | 88 hotTreeShakingTime ~/= numberOfTrials; |
91 | 89 |
92 var coldShakingMs = coldTreeShakingTime ~/ 1000; | 90 var coldShakingMs = coldTreeShakingTime ~/ 1000; |
93 var coldHierarchyMs = coldHierarchyTime ~/ 1000; | 91 var coldHierarchyMs = coldHierarchyTime ~/ 1000; |
94 var hotShakingMs = hotTreeShakingTime ~/ 1000; | 92 var hotShakingMs = hotTreeShakingTime ~/ 1000; |
95 var hotHierarchyMs = hotHierarchyTime ~/ 1000; | 93 var hotHierarchyMs = hotHierarchyTime ~/ 1000; |
96 | 94 |
97 print(''' | 95 print(''' |
98 build.cold $coldShakingMs ms ($coldHierarchyMs ms from hierarchy) | 96 build.cold $coldShakingMs ms ($coldHierarchyMs ms from hierarchy) |
99 build.hot $hotShakingMs ms ($hotHierarchyMs ms from hierarchy)'''); | 97 build.hot $hotShakingMs ms ($hotHierarchyMs ms from hierarchy)'''); |
100 } | 98 } |
OLD | NEW |