Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
2b25e291
Unverified
Commit
2b25e291
authored
Aug 15, 2020
by
Remi Rousselet
Committed by
GitHub
Aug 15, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add benchmark for ChangeNotifier.notifyListeners (#62715)
parent
da98319d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
118 additions
and
1 deletion
+118
-1
change_notifier_bench.dart
...microbenchmarks/lib/foundation/change_notifier_bench.dart
+116
-0
microbenchmarks.dart
dev/devicelab/lib/tasks/microbenchmarks.dart
+2
-1
No files found.
dev/benchmarks/microbenchmarks/lib/foundation/change_notifier_bench.dart
0 → 100644
View file @
2b25e291
// Copyright 2014 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/foundation.dart'
;
import
'../common.dart'
;
const
int
_kNumIterations
=
1000
;
const
double
_scale
=
1000.0
/
_kNumIterations
;
const
int
_kNumWarmUp
=
100
;
void
main
(
)
{
assert
(
false
,
"Don't run benchmarks in checked mode! Use 'flutter run --release'."
);
void
listener
()
{}
void
listener2
()
{}
void
listener3
()
{}
void
listener4
()
{}
void
listener5
()
{}
// Warm up lap
for
(
int
i
=
0
;
i
<
_kNumWarmUp
;
i
+=
1
)
{
_Notifier
()
..
addListener
(
listener
)
..
addListener
(
listener2
)
..
addListener
(
listener3
)
..
addListener
(
listener4
)
..
addListener
(
listener5
)
..
notify
()
..
removeListener
(
listener
)
..
removeListener
(
listener2
)
..
removeListener
(
listener3
)
..
removeListener
(
listener4
)
..
removeListener
(
listener5
);
}
final
Stopwatch
addListenerWatch
=
Stopwatch
();
final
Stopwatch
removeListenerWatch
=
Stopwatch
();
final
Stopwatch
notifyListenersWatch
=
Stopwatch
();
final
BenchmarkResultPrinter
printer
=
BenchmarkResultPrinter
();
for
(
int
listenersCount
=
0
;
listenersCount
<=
5
;
listenersCount
++)
{
for
(
int
j
=
0
;
j
<
_kNumIterations
;
j
+=
1
)
{
final
_Notifier
notifier
=
_Notifier
();
addListenerWatch
.
start
();
notifier
.
addListener
(
listener
);
if
(
listenersCount
>
1
)
notifier
.
addListener
(
listener2
);
if
(
listenersCount
>
2
)
notifier
.
addListener
(
listener3
);
if
(
listenersCount
>
3
)
notifier
.
addListener
(
listener4
);
if
(
listenersCount
>
4
)
notifier
.
addListener
(
listener5
);
addListenerWatch
.
stop
();
notifyListenersWatch
.
start
();
notifier
.
notify
();
notifyListenersWatch
.
stop
();
removeListenerWatch
.
start
();
// Remove listeners in reverse order to evaluate the worse-case scenario:
// the listener removed is the last listener
if
(
listenersCount
>
4
)
notifier
.
removeListener
(
listener5
);
if
(
listenersCount
>
3
)
notifier
.
removeListener
(
listener4
);
if
(
listenersCount
>
2
)
notifier
.
removeListener
(
listener3
);
if
(
listenersCount
>
1
)
notifier
.
removeListener
(
listener2
);
notifier
.
removeListener
(
listener
);
removeListenerWatch
.
stop
();
}
final
int
notifyListener
=
notifyListenersWatch
.
elapsedMicroseconds
;
notifyListenersWatch
.
reset
();
final
int
addListenerElapsed
=
addListenerWatch
.
elapsedMicroseconds
;
addListenerWatch
.
reset
();
final
int
removeListenerElapsed
=
removeListenerWatch
.
elapsedMicroseconds
;
removeListenerWatch
.
reset
();
printer
.
addResult
(
description:
'addListener (
$listenersCount
listeners)'
,
value:
addListenerElapsed
*
_scale
,
unit:
'ns per iteration'
,
name:
'addListener
${listenersCount}
_iteration'
,
);
printer
.
addResult
(
description:
'removeListener (
$listenersCount
listeners)'
,
value:
removeListenerElapsed
*
_scale
,
unit:
'ns per iteration'
,
name:
'removeListener
${listenersCount}
_iteration'
,
);
printer
.
addResult
(
description:
'notifyListener (
$listenersCount
listeners)'
,
value:
notifyListener
*
_scale
,
unit:
'ns per iteration'
,
name:
'notifyListener
${listenersCount}
_iteration'
,
);
}
printer
.
printToStdout
();
}
class
_Notifier
extends
ChangeNotifier
{
void
notify
()
=>
notifyListeners
();
}
dev/devicelab/lib/tasks/microbenchmarks.dart
View file @
2b25e291
...
@@ -54,7 +54,8 @@ TaskFunction createMicrobenchmarkTask() {
...
@@ -54,7 +54,8 @@ TaskFunction createMicrobenchmarkTask() {
...
await
_runMicrobench
(
'lib/stocks/animation_bench.dart'
),
...
await
_runMicrobench
(
'lib/stocks/animation_bench.dart'
),
...
await
_runMicrobench
(
'lib/language/sync_star_bench.dart'
),
...
await
_runMicrobench
(
'lib/language/sync_star_bench.dart'
),
...
await
_runMicrobench
(
'lib/language/sync_star_semantics_bench.dart'
),
...
await
_runMicrobench
(
'lib/language/sync_star_semantics_bench.dart'
),
};
...
await
_runMicrobench
(
'lib/foundation/change_notifier_bench.dart'
),
};
return
TaskResult
.
success
(
allResults
,
benchmarkScoreKeys:
allResults
.
keys
.
toList
());
return
TaskResult
.
success
(
allResults
,
benchmarkScoreKeys:
allResults
.
keys
.
toList
());
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment