@@ -4,7 +4,7 @@ import "dart:typed_data";
4
4
import "dart:math" ;
5
5
6
6
main () {
7
- var byteList = new Uint8List (1024 * 1024 * 5 );
7
+ var byteList = new Uint8List (1024 * 1024 * 50 );
8
8
var random = new Random ();
9
9
for (var i = 0 ; i < byteList.lengthInBytes; i++ ) {
10
10
byteList[i] = random.nextInt (255 );
@@ -35,14 +35,40 @@ main() {
35
35
unpack (encoded);
36
36
}
37
37
38
+ var watch = new Stopwatch ();
39
+ watch.start ();
40
+ var times = < List <int >> [];
41
+ for (var i = 1 ; i <= 5 ; i++ ) {
42
+ times.add (go (input));
43
+ }
44
+ watch.stop ();
45
+
46
+ var totalEncodeTime = 0 ;
47
+ var totalDecodeTime = 0 ;
48
+ for (var time in times) {
49
+ totalEncodeTime += time[0 ];
50
+ totalDecodeTime += time[1 ];
51
+ }
52
+ var avgEncodeTime = totalEncodeTime / times.length;
53
+ var avgDecodeTime = totalDecodeTime / times.length;
54
+
55
+ print ("Took an average of ${(avgEncodeTime / 1000 ).toStringAsFixed (2 )}ms to encode." );
56
+ print ("Took an average of ${(avgDecodeTime / 1000 ).toStringAsFixed (2 )}ms to decode." );
57
+ }
58
+
59
+ List <int > go (input) {
60
+ var out = < int > [];
38
61
var watch = new Stopwatch ();
39
62
watch.start ();
40
63
var encoded = pack (input);
41
64
watch.stop ();
42
65
print ("Took ${watch .elapsedMicroseconds / 1000 }ms to encode." );
66
+ out.add (watch.elapsedMicroseconds);
43
67
watch.reset ();
44
68
watch.start ();
45
69
var decoded = unpack (encoded);
46
70
watch.stop ();
47
71
print ("Took ${watch .elapsedMicroseconds / 1000 }ms to decode." );
72
+ out.add (watch.elapsedMicroseconds);
73
+ return out;
48
74
}
0 commit comments