Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(525)

Side by Side Diff: packages/petitparser/test/json_benchmark.dart

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « packages/petitparser/test/debug_test.dart ('k') | packages/petitparser/test/json_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 library petitparser.test.json_benchmark;
2
3 import 'package:petitparser/json.dart';
4
5 import 'dart:convert';
6
7 double benchmark(Function function, [int warmup = 1000, int milliseconds = 5000] ) {
8 var count = 0;
9 var elapsed = 0;
10 var watch = new Stopwatch();
11 while (warmup-- > 0) {
12 function();
13 }
14 watch.start();
15 while (elapsed < milliseconds) {
16 function();
17 elapsed = watch.elapsedMilliseconds;
18 count++;
19 }
20 return elapsed / count;
21 }
22
23 const jsonEvent = '{"type": "change", "eventPhase": 2, "bubbles": true, "cancela ble": true, '
24 '"timeStamp": 0, "CAPTURING_PHASE": 1, "AT_TARGET": 2, "BUBBLING_PHASE": 3, "isTrusted": '
25 'true, "MOUSEDOWN": 1, "MOUSEUP": 2, "MOUSEOVER": 4, "MOUSEOUT": 8, "MOUSEMO VE": 16, '
26 '"MOUSEDRAG": 32, "CLICK": 64, "DBLCLICK": 128, "KEYDOWN": 256, "KEYUP": 512 , "KEYPRESS": '
27 '1024, "DRAGDROP": 2048, "FOCUS": 4096, "BLUR": 8192, "SELECT": 16384, "CHAN GE": 32768, '
28 '"RESET": 65536, "SUBMIT": 131072, "SCROLL": 262144, "LOAD": 524288, "UNLOAD ": 1048576, '
29 '"XFER_DONE": 2097152, "ABORT": 4194304, "ERROR": 8388608, "LOCATE": 1677721 6, "MOVE": '
30 '33554432, "RESIZE": 67108864, "FORWARD": 134217728, "HELP": 268435456, "BAC K": 536870912, '
31 '"TEXT": 1073741824, "ALT_MASK": 1, "CONTROL_MASK": 2, "SHIFT_MASK": 4, "MET A_MASK": 8}';
32
33 final JsonParser json = new JsonParser();
34
35 dynamic native(String input) => JSON.decode(input);
36 dynamic custom(String input) => json.parse(input).value;
37
38 void main() {
39 var nativeResult = native(jsonEvent);
40 var customResult = custom(jsonEvent);
41
42 if (nativeResult.toString() != customResult.toString()) {
43 print('Results not matching!');
44 print(' Native: $nativeResult');
45 print(' Custom: $customResult');
46 return;
47 }
48
49 var nativeTime = benchmark(() => native(jsonEvent));
50 var customTime = benchmark(() => custom(jsonEvent));
51 var ratio = customTime / nativeTime;
52
53 print('Slowdown: ${ratio.toStringAsFixed(1)}');
54 print('Native: ${nativeTime.toStringAsFixed(6)}');
55 print('Custom: ${customTime.toStringAsFixed(6)}');
56 }
OLDNEW
« no previous file with comments | « packages/petitparser/test/debug_test.dart ('k') | packages/petitparser/test/json_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698