Skip to content

Upgrade to support dart 2.0 #5

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
217 changes: 48 additions & 169 deletions example/benchmark.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "dart:convert";
import "dart:io";

import "package:msgpack/msgpack.dart";
import "dart:io";

const int TIMES = 10000;

Expand All @@ -18,8 +18,7 @@ class Fraction {
return new Fraction(numerator / cd, denominator / cd);
}

Fraction cross(Fraction other) =>
new Fraction(other.denominator * numerator, other.numerator * denominator);
Fraction cross(Fraction other) => new Fraction(other.denominator * numerator, other.numerator * denominator);

@override
String toString() => "${numerator}/${denominator}";
Expand All @@ -30,16 +29,12 @@ class Fraction {
main(List<String> args) async {
print("Warming Up...");
for (var i = 0; i < TIMES; i++) {
var packed = pack({
"hello": "world"
});
var packed = pack({"hello": "world"});

var json = JSON.encode({
"hello": "world"
});
var jsonValue = json.encode({"hello": "world"});

unpack(packed);
JSON.decode(json);
json.decode(jsonValue);
}

if (args.contains("--savings")) {
Expand All @@ -48,7 +43,7 @@ main(List<String> args) async {
numbers.add(i);
}

var jsonBytes = UTF8.encode(JSON.encode(numbers)).length;
var jsonBytes = utf8.encode(json.encode(numbers)).length;
var msgpackBytes = pack(numbers).length;
var fract = new Fraction(jsonBytes, msgpackBytes);
fract = fract.reduce();
Expand All @@ -61,168 +56,52 @@ main(List<String> args) async {
var objects = {
"One": 1,
"Five Hundred Thousand": 500000,
"List of Small Integers": [
1,
2,
3
],
"Simple Map": {
"hello": "world"
},
"List of Small Integers": [1, 2, 3],
"Simple Map": {"hello": "world"},
"5.02817472928": 5.02817472928,
"Multiple Type Map": {
"String": "Hello World",
"Integer": 1,
"Double": 2.0154,
"Array": const [
1,
2,
3,
"Hello"
]
"Array": const [1, 2, 3, "Hello"]
},
"Medium Data": {
"/downstream/wemo/CoffeeMaker-1_0-221421S0000731/Brew_Age": [
[
1440366101049,
-123881
],
[
1440366102047,
-123882
],
[
1440366103049,
-123883
],
[
1440366104046,
-123884
],
[
1440366105062,
-123885
],
[
1440366106050,
-123886
],
[
1440366107046,
-123887
],
[
1440366108045,
-123888
],
[
1440366109036,
-123889
],
[
1440366110048,
-123890
],
[
1440366111047,
-123891
],
[
1440366112037,
-123892
],
[
1440366113048,
-123893
],
[
1440366114048,
-123894
],
[
1440366115046,
-123895
],
[
1440366116044,
-123896
],
[
1440366117045,
-123897
],
[
1440366118049,
-123898
],
[
1440366119046,
-123899
],
[
1440366120042,
-123900
],
[
1440366121047,
-123901
],
[
1440366122048,
-123902
],
[
1440366123046,
-123903
],
[
1440366124055,
-123904
],
[
1440366126059,
-123906
],
[
1440366127054,
-123907
],
[
1440366128047,
-123908
],
[
1440366129051,
-123909
],
[
1440366130051,
-123910
],
[
1440366131048,
-123911
],
[
1440366132050,
-123912
],
[
1440366133032,
-123913
],
[
1440366134045,
-123914
],
[
1440366135050,
-123915
],
[
1440366136049,
-123916
]
[1440366101049, -123881],
[1440366102047, -123882],
[1440366103049, -123883],
[1440366104046, -123884],
[1440366105062, -123885],
[1440366106050, -123886],
[1440366107046, -123887],
[1440366108045, -123888],
[1440366109036, -123889],
[1440366110048, -123890],
[1440366111047, -123891],
[1440366112037, -123892],
[1440366113048, -123893],
[1440366114048, -123894],
[1440366115046, -123895],
[1440366116044, -123896],
[1440366117045, -123897],
[1440366118049, -123898],
[1440366119046, -123899],
[1440366120042, -123900],
[1440366121047, -123901],
[1440366122048, -123902],
[1440366123046, -123903],
[1440366124055, -123904],
[1440366126059, -123906],
[1440366127054, -123907],
[1440366128047, -123908],
[1440366129051, -123909],
[1440366130051, -123910],
[1440366131048, -123911],
[1440366132050, -123912],
[1440366133032, -123913],
[1440366134045, -123914],
[1440366135050, -123915],
[1440366136049, -123916]
]
}
};
Expand All @@ -249,7 +128,7 @@ main(List<String> args) async {

testObjectDecode(String desc, input) {
print("${desc}:");
var packedJson = JSON.encode(input);
var packedJson = json.encode(input);
var packed = pack(input);
var watch = new Stopwatch();
var times = [];
Expand All @@ -274,7 +153,7 @@ testObjectDecode(String desc, input) {
for (var i = 1; i <= TIMES; i++) {
watch.reset();
watch.start();
JSON.decode(packedJson);
json.decode(packedJson);
watch.stop();
times.add(watch.elapsedMicroseconds);
}
Expand Down Expand Up @@ -320,12 +199,12 @@ testObjectEncode(String desc, input) {
print(" Shortest Time: ${times.first} microseconds (${times.first / 1000}ms)");
print(" Size: ${size} bytes");
watch.reset();
size = UTF8.encode(JSON.encode(input)).length;
size = utf8.encode(json.encode(input)).length;
times.clear();
for (var i = 1; i <= TIMES; i++) {
watch.reset();
watch.start();
JSON.encode(input);
json.encode(input);
watch.stop();
times.add(watch.elapsedMicroseconds);
}
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: msgpack
description: MsgPack for Dart
version: 0.9.0
version: 1.0.0
authors:
- Kenneth Endfinger <kaendfinger@gmail.com>
- Dan Ellis <dan@danellis.me>
homepage: https://github.com/DirectMyFile/msgpack.dart
dev_dependencies:
test: "^0.12.0"
test: '^1.0.0'
Loading