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

Unified Diff: packages/petitparser/test/json_benchmark.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/petitparser/test/json_benchmark.dart
diff --git a/packages/petitparser/test/json_benchmark.dart b/packages/petitparser/test/json_benchmark.dart
new file mode 100644
index 0000000000000000000000000000000000000000..aca069e3da3a3403b744eb57b2401de7a67b5287
--- /dev/null
+++ b/packages/petitparser/test/json_benchmark.dart
@@ -0,0 +1,56 @@
+library petitparser.test.json_benchmark;
+
+import 'package:petitparser/json.dart';
+
+import 'dart:convert';
+
+double benchmark(Function function, [int warmup = 1000, int milliseconds = 5000]) {
+ var count = 0;
+ var elapsed = 0;
+ var watch = new Stopwatch();
+ while (warmup-- > 0) {
+ function();
+ }
+ watch.start();
+ while (elapsed < milliseconds) {
+ function();
+ elapsed = watch.elapsedMilliseconds;
+ count++;
+ }
+ return elapsed / count;
+}
+
+const jsonEvent = '{"type": "change", "eventPhase": 2, "bubbles": true, "cancelable": true, '
+ '"timeStamp": 0, "CAPTURING_PHASE": 1, "AT_TARGET": 2, "BUBBLING_PHASE": 3, "isTrusted": '
+ 'true, "MOUSEDOWN": 1, "MOUSEUP": 2, "MOUSEOVER": 4, "MOUSEOUT": 8, "MOUSEMOVE": 16, '
+ '"MOUSEDRAG": 32, "CLICK": 64, "DBLCLICK": 128, "KEYDOWN": 256, "KEYUP": 512, "KEYPRESS": '
+ '1024, "DRAGDROP": 2048, "FOCUS": 4096, "BLUR": 8192, "SELECT": 16384, "CHANGE": 32768, '
+ '"RESET": 65536, "SUBMIT": 131072, "SCROLL": 262144, "LOAD": 524288, "UNLOAD": 1048576, '
+ '"XFER_DONE": 2097152, "ABORT": 4194304, "ERROR": 8388608, "LOCATE": 16777216, "MOVE": '
+ '33554432, "RESIZE": 67108864, "FORWARD": 134217728, "HELP": 268435456, "BACK": 536870912, '
+ '"TEXT": 1073741824, "ALT_MASK": 1, "CONTROL_MASK": 2, "SHIFT_MASK": 4, "META_MASK": 8}';
+
+final JsonParser json = new JsonParser();
+
+dynamic native(String input) => JSON.decode(input);
+dynamic custom(String input) => json.parse(input).value;
+
+void main() {
+ var nativeResult = native(jsonEvent);
+ var customResult = custom(jsonEvent);
+
+ if (nativeResult.toString() != customResult.toString()) {
+ print('Results not matching!');
+ print(' Native: $nativeResult');
+ print(' Custom: $customResult');
+ return;
+ }
+
+ var nativeTime = benchmark(() => native(jsonEvent));
+ var customTime = benchmark(() => custom(jsonEvent));
+ var ratio = customTime / nativeTime;
+
+ print('Slowdown: ${ratio.toStringAsFixed(1)}');
+ print('Native: ${nativeTime.toStringAsFixed(6)}');
+ print('Custom: ${customTime.toStringAsFixed(6)}');
+}
« 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