-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some profiling instrumentation to the exhaustiveness checker.
- Loading branch information
1 parent
7c0ec27
commit 0df870d
Showing
5 changed files
with
69 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
6 changes: 4 additions & 2 deletions
6
working/0546-patterns/exhaustiveness_prototype/lib/intersect.dart
This file contains 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
47 changes: 47 additions & 0 deletions
47
working/0546-patterns/exhaustiveness_prototype/lib/profile.dart
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:math'; | ||
|
||
var enabled = false; | ||
|
||
final _counts = <String, int>{}; | ||
|
||
void count(String name, [String? subname]) { | ||
if (!enabled) return; | ||
_counts.putIfAbsent(name, () => 0); | ||
_counts[name] = _counts[name]! + 1; | ||
|
||
if (subname != null) { | ||
count('$name/$subname'); | ||
} | ||
} | ||
|
||
void run(void Function() callback) { | ||
reset(); | ||
try { | ||
callback(); | ||
} finally { | ||
log(); | ||
reset(); | ||
} | ||
} | ||
|
||
void reset() { | ||
_counts.clear(); | ||
} | ||
|
||
void log() { | ||
var names = _counts.keys.toList(); | ||
names.sort(); | ||
var nameLength = | ||
names.fold<int>(0, (length, name) => max(length, name.length)); | ||
var countLength = _counts.values | ||
.fold<int>(0, (length, count) => max(length, count.toString().length)); | ||
|
||
for (var name in names) { | ||
print('${name.padRight(nameLength)} = ' | ||
'${_counts[name].toString().padLeft(countLength)}'); | ||
} | ||
} |
This file contains 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
This file contains 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