Files
sdk/pkg/front_end/test/simple_stats.dart
T
Jens Johansen 1a218c0103 [kernel/CFE] Dill extractor tool; CFE compile dir tool; fixes for stats
This CL adds two tools
* A dill extractor tool which extracts the source files inside the dill
  to a new directory, trying to recrease the package config too so the
  sources can be compiled again. Thought as being useful for doing
  benchmarks between the CFE and the analyzer to make sure they look at
  the exact same source files. No more. No less.
* A CFE compile entry point that compiles all files in a directory.
  Again thought as being useful to compare the CFE with the Analyzer.

Additionally it introduces "--gcs=<int>" to `benchmarker.dart` so it can
do multiple runs and do statistics on combined gc times.

Usage example:

```
$ out/ReleaseX64/dart pkg/front_end/tool/compile.dart pkg/front_end/tool/compile.dart

$ out/ReleaseX64/dart-sdk/bin/dart pkg/kernel/bin/dill_extractor.dart pkg/front_end/tool/compile.dart.dill /tmp/extracted_compile_dart_compile
Done. Wrote 687 source files.

$ out/ReleaseX64/dart-sdk/bin/dart compile aot-snapshot pkg/front_end/tool/compile_files_in_folders.dart
Generated: [...]/pkg/front_end/tool/compile_files_in_folders.aot

$ out/ReleaseX64/dart-sdk/bin/dart compile aot-snapshot pkg/analyzer_cli/bin/analyzer.dart
Generated: [...]/pkg/analyzer_cli/bin/analyzer.aot

$ time out/ReleaseX64/dart-sdk/bin/dartaotruntime pkg/front_end/tool/compile_files_in_folders.aot /tmp/extracted_compile_dart_compile/
Got 626 libraries.
Finished in 0:00:03.496817

real    0m3.530s
user    0m4.985s
sys     0m0.257s

$ time out/ReleaseX64/dart-sdk/bin/dartaotruntime pkg/analyzer_cli/bin/analyzer.aot /tmp/extracted_compile_dart_compile/
Analyzing /tmp/extracted_compile_dart_compile...
  warning • Target of URI doesn't exist: 'package:compiler/src/io/source_file.dart'. • package:_fe_analyzer_shared/src/scanner/utf8_bytes_scanner.dart:5:16 • uri_does_not_exist_in_doc_import
1 warning found.

real    0m8.479s
user    0m9.997s
sys     0m1.048s


$ out/ReleaseX64/dart pkg/front_end/tool/benchmarker.dart --silent --iterations=10 --gcs=5 --snapshot=pkg/front_end/tool/compile_files_in_folders.aot --snapshot=pkg/analyzer_cli/bin/analyzer.aot --arguments="/tmp/extracted_compile_dart_compile/"
Will now run 10 iterations with 2 snapshots.
..............................

Comparing snapshot #1 (compile_files_in_folders.aot) with snapshot #2 (analyzer.aot)
msec task-clock:u: 141.1012% +/- 1.5550% (6281.55 +/- 69.22) (4451.81 -> 10733.36)
page-faults:u: 47.5414% +/- 0.7786% (45602.90 +/- 746.84) (95922.50 -> 141525.40)
cycles:u: 119.3182% +/- 1.5751% (22131655652.90 +/- 292155654.08) (18548436164.50 -> 40680091817.40)
instructions:u: 140.2463% +/- 0.0340% (30410953910.60 +/- 7375789.67) (21683959961.20 -> 52094913871.80)
branch-misses:u: 97.9816% +/- 7.3049% (73071988.00 +/- 5447773.30) (74577266.40 -> 147649254.40)
seconds time elapsed: 141.0789% +/- 1.5479% (6.28 +/- 0.07) (4.45 -> 10.74)
seconds user: 124.4165% +/- 1.8322% (5.31 +/- 0.08) (4.26 -> 9.57)
seconds sys: 521.0422% +/- 17.4291% (0.98 +/- 0.03) (0.19 -> 1.16)
Comparing GC:
Combined GC time: 63.8901% +/- 1.2946% (1008.76 +/- 20.44) (1578.90 -> 2587.66)
```

(note that benchmarker passes `--deterministic` and limits the run to one cpu, both of which (potentially) makes it slower --- which is why the stats say 4.45 s instead of ~3.53 s and 10.74 s instead of ~8.48 s)

Change-Id: I785620ce40af11ca1f7b6c88a0ac863b2200f7d3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449180
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2025-09-11 05:33:04 -07:00

178 lines
5.4 KiB
Dart

// Copyright (c) 2020, 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' as math;
class SimpleTTestStat {
static TTestResult ttest(List<num> a, List<num> b) {
num aSum = sum(a);
num bSum = sum(b);
int aCount = a.length;
int bCount = b.length;
double aMean = aSum / aCount;
double bMean = bSum / bCount;
double aVariance = variance(a);
double bVariance = variance(b);
double pooledStandardDeviation = math.sqrt((aVariance + bVariance) / 2);
double pooledSampleStandardError =
pooledStandardDeviation * math.sqrt(1 / aCount + 1 / bCount);
double diffMean = aMean - bMean;
// Difference in population mean with confidence interval:
// μ1 - μ2 = (M1 - M2) ± t * standardError
double confidence =
tTableTwoTails_0_05(aCount + bCount - 2) * pooledSampleStandardError;
if (confidence < diffMean.abs()) {
double percentDiff = diffMean * 100 / bMean;
double percentDiffConfidence = confidence * 100 / bMean;
return new TTestResult(
true,
percentDiff,
percentDiffConfidence,
diffMean,
confidence,
aMean,
bMean,
);
} else {
return new TTestResult(false, 0, 0, 0, 0, 0, 0);
}
}
static double average(List<num> data) {
return sum(data) / data.length;
}
static double variance(List<num> data) {
int count = data.length;
double average = sum(data) / count;
double diffSquareSum = 0;
for (num value in data) {
double diff = value - average;
double squared = diff * diff;
diffSquareSum += squared;
}
double variance = diffSquareSum / (count - 1);
return variance;
}
static num sum(List<num> data) {
num result = 0;
for (num value in data) {
result += value;
}
return result;
}
static double tTableTwoTails_0_05(int value) {
// TODO: Maybe actually calculate this? I haven't looked that up.
// These numbers are from google sheets "=TINV(0.05, value)"
if (value < 1) throw "value has to be > 0";
if (value == 1) return 12.70620474;
if (value == 2) return 4.30265273;
if (value == 3) return 3.182446305;
if (value == 4) return 2.776445105;
if (value == 5) return 2.570581836;
if (value == 6) return 2.446911851;
if (value == 7) return 2.364624252;
if (value == 8) return 2.306004135;
if (value == 9) return 2.262157163;
if (value == 10) return 2.228138852;
if (value == 11) return 2.20098516;
if (value == 12) return 2.17881283;
if (value == 13) return 2.160368656;
if (value == 14) return 2.144786688;
if (value == 15) return 2.131449546;
if (value == 16) return 2.119905299;
if (value == 17) return 2.109815578;
if (value == 18) return 2.10092204;
if (value == 19) return 2.093024054;
if (value == 20) return 2.085963447;
if (value <= 30) return 2.042272456;
if (value <= 40) return 2.02107539;
if (value <= 50) return 2.008559112;
if (value <= 60) return 2.000297822;
if (value <= 70) return 1.994437112;
if (value <= 80) return 1.990063421;
if (value <= 80) return 1.990063421;
if (value <= 90) return 1.986674541;
if (value <= 100) return 1.983971519;
if (value <= 150) return 1.975905331;
if (value <= 200) return 1.971896224;
if (value <= 250) return 1.969498393;
if (value <= 500) return 1.964719837;
if (value <= 1000) return 1.962339081;
if (value <= 10000) return 1.96020124;
if (value <= 100000) return 1.959987708;
if (value <= 1000000) return 1.959966357;
return 1.959964228;
}
}
class TTestResult {
final bool significant;
final double percentDiff;
final double percentDiffConfidence;
final double diff;
final double confidence;
final double aMean;
final double bMean;
TTestResult(
this.significant,
this.percentDiff,
this.percentDiffConfidence,
this.diff,
this.confidence,
this.aMean,
this.bMean,
);
@override
String toString() {
if (significant) {
double leastConfidentChange;
if (diff < 0) {
leastConfidentChange = diff + confidence;
} else {
leastConfidentChange = diff - confidence;
}
return "TTestResult[significant: "
"${_format(percentDiff)}% +/- ${_format(percentDiffConfidence)}% "
"(${_format(diff)} +/- ${_format(confidence)}) "
"(at least ${_format(leastConfidentChange)})]";
} else {
return "TTestResult[not significant]";
}
}
String _format(double d, {int fractionDigits = 2}) {
return d.toStringAsFixed(fractionDigits);
}
String? percentChangeIfSignificant({int fractionDigits = 2}) {
if (!significant) return null;
return "${_format(percentDiff, fractionDigits: fractionDigits)}% "
"+/- "
"${_format(percentDiffConfidence, fractionDigits: fractionDigits)}%";
}
String? valueChangeIfSignificant({int fractionDigits = 2}) {
if (!significant) return null;
return "${_format(diff, fractionDigits: fractionDigits)} "
"+/- "
"${_format(confidence, fractionDigits: fractionDigits)}";
}
String? meanChangeStringIfSignificant({int fractionDigits = 2}) {
if (!significant) return null;
return "${_format(bMean, fractionDigits: fractionDigits)} "
"-> "
"${_format(aMean, fractionDigits: fractionDigits)}";
}
}