| 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(coreTypes, program, | 61 var shaker = new TreeShaker(coreTypes, sharedClassHierarchy, program, |
| 62 hierarchy: sharedClassHierarchy, strongMode: strongMode); | 62 strongMode: strongMode); |
| 63 if (options['diagnose']) { | 63 if (options['diagnose']) { |
| 64 print(shaker.getDiagnosticString()); | 64 print(shaker.getDiagnosticString()); |
| 65 } | 65 } |
| 66 shaker = null; | 66 shaker = null; |
| 67 int coldTreeShakingTime = watch.elapsedMicroseconds; | 67 int coldTreeShakingTime = watch.elapsedMicroseconds; |
| 68 | 68 |
| 69 ClassHierarchy getClassHierarchy() { | 69 ClassHierarchy getClassHierarchy() { |
| 70 return options['from-scratch'] | 70 return options['from-scratch'] |
| 71 ? buildClassHierarchy() | 71 ? buildClassHierarchy() |
| 72 : sharedClassHierarchy; | 72 : sharedClassHierarchy; |
| 73 } | 73 } |
| 74 | 74 |
| 75 const int numberOfTrials = 50; | 75 const int numberOfTrials = 50; |
| 76 int hotHierarchyTime = 0; | 76 int hotHierarchyTime = 0; |
| 77 int hotTreeShakingTime = 0; | 77 int hotTreeShakingTime = 0; |
| 78 watch.reset(); | 78 watch.reset(); |
| 79 for (int i = 0; i < numberOfTrials; i++) { | 79 for (int i = 0; i < numberOfTrials; i++) { |
| 80 watch.reset(); | 80 watch.reset(); |
| 81 var hierarchy = getClassHierarchy(); | 81 var hierarchy = getClassHierarchy(); |
| 82 hotHierarchyTime += watch.elapsedMicroseconds; | 82 hotHierarchyTime += watch.elapsedMicroseconds; |
| 83 new TreeShaker(coreTypes, program, | 83 new TreeShaker(coreTypes, hierarchy, program, strongMode: strongMode); |
| 84 hierarchy: hierarchy, strongMode: strongMode); | |
| 85 hotTreeShakingTime += watch.elapsedMicroseconds; | 84 hotTreeShakingTime += watch.elapsedMicroseconds; |
| 86 } | 85 } |
| 87 hotHierarchyTime ~/= numberOfTrials; | 86 hotHierarchyTime ~/= numberOfTrials; |
| 88 hotTreeShakingTime ~/= numberOfTrials; | 87 hotTreeShakingTime ~/= numberOfTrials; |
| 89 | 88 |
| 90 var coldShakingMs = coldTreeShakingTime ~/ 1000; | 89 var coldShakingMs = coldTreeShakingTime ~/ 1000; |
| 91 var coldHierarchyMs = coldHierarchyTime ~/ 1000; | 90 var coldHierarchyMs = coldHierarchyTime ~/ 1000; |
| 92 var hotShakingMs = hotTreeShakingTime ~/ 1000; | 91 var hotShakingMs = hotTreeShakingTime ~/ 1000; |
| 93 var hotHierarchyMs = hotHierarchyTime ~/ 1000; | 92 var hotHierarchyMs = hotHierarchyTime ~/ 1000; |
| 94 | 93 |
| 95 print(''' | 94 print(''' |
| 96 build.cold $coldShakingMs ms ($coldHierarchyMs ms from hierarchy) | 95 build.cold $coldShakingMs ms ($coldHierarchyMs ms from hierarchy) |
| 97 build.hot $hotShakingMs ms ($hotHierarchyMs ms from hierarchy)'''); | 96 build.hot $hotShakingMs ms ($hotHierarchyMs ms from hierarchy)'''); |
| 98 } | 97 } |
| OLD | NEW |