-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[web_benchmarks] Add percentile computations to benchmark scores #7760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
13045f8
Add percentile computations to benchmark scores
kenzieschmoll a8eca34
Fix dart doc typo
kenzieschmoll a4cf82a
review comments
kenzieschmoll da3735f
Merge branch 'main' of github.com:flutter/packages into percentiles
kenzieschmoll d26df9b
fix test
kenzieschmoll df56a51
review comments
kenzieschmoll 6c12600
Refactor computation code
kenzieschmoll 6e0abb0
Prep for 3.1.0 publish.
kenzieschmoll f2caad2
organize imports
kenzieschmoll File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,44 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:collection/collection.dart'; | ||
|
|
||
| // TODO(kenz): move the time series logic from recorder.dart into this file for | ||
| // better code separation. | ||
|
|
||
| /// Computes the percentile threshold in [values] for the given [percentiles]. | ||
| /// | ||
| /// Each value in [percentiles] should be between 0.0 and 1.0. | ||
| /// | ||
| /// Returns a [Map] of percentile values to the computed value from [values]. | ||
| Map<double, double> computePercentiles( | ||
| String label, | ||
| List<double> percentiles, | ||
| Iterable<double> values, | ||
| ) { | ||
| if (values.isEmpty) { | ||
| throw StateError( | ||
| '$label: attempted to compute a percentile of an empty value list.', | ||
| ); | ||
| } | ||
| for (final double percentile in percentiles) { | ||
| if (percentile < 0.0 || percentile > 1.0) { | ||
| throw StateError( | ||
| '$label: attempted to compute a percentile for an invalid ' | ||
| 'value: $percentile', | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| final List<double> sorted = | ||
| values.sorted((double a, double b) => a.compareTo(b)); | ||
| final Map<double, double> computed = <double, double>{}; | ||
| for (final double percentile in percentiles) { | ||
| final int percentileIndex = | ||
| (sorted.length * percentile).round().clamp(0, sorted.length - 1); | ||
| computed[percentile] = sorted[percentileIndex]; | ||
| } | ||
|
|
||
| return computed; | ||
| } |
This file contains hidden or 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,24 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:web_benchmarks/src/timeseries.dart'; | ||
|
|
||
| void main() { | ||
| group('Timeseries', () { | ||
| test('computePercentiles', () { | ||
| final Map<double, double> computed = computePercentiles( | ||
| 'test', | ||
| <double>[0.0, 0.5, 0.9, 0.95, 1.0], | ||
| List<double>.generate(100, (int i) => i.toDouble()), | ||
| ); | ||
| expect(computed.length, 5); | ||
| expect(computed[0.0], 0.0); | ||
| expect(computed[0.5], 50.0); | ||
| expect(computed[0.9], 90.0); | ||
| expect(computed[0.95], 95.0); | ||
| expect(computed[1.0], 99.0); | ||
| }); | ||
| }); | ||
| } |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.