|
|
@ -11,10 +11,11 @@
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
// limitations under the License.
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'dart:typed_data';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
import 'dart:isolate';
|
|
|
|
import 'dart:isolate';
|
|
|
|
import 'dart:math';
|
|
|
|
import 'dart:math';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class DataTransferPageStarter extends StatelessWidget {
|
|
|
|
class DataTransferPageStarter extends StatelessWidget {
|
|
|
|
@override
|
|
|
|
@override
|
|
|
@ -67,7 +68,7 @@ class DataTransferIsolateController extends ChangeNotifier {
|
|
|
|
SendPort _newIceSP;
|
|
|
|
SendPort _newIceSP;
|
|
|
|
|
|
|
|
|
|
|
|
final currentProgress = <String>[];
|
|
|
|
final currentProgress = <String>[];
|
|
|
|
bool running = false;
|
|
|
|
int runningTest = 0;
|
|
|
|
Stopwatch _timer = Stopwatch();
|
|
|
|
Stopwatch _timer = Stopwatch();
|
|
|
|
double progressPercent = 0;
|
|
|
|
double progressPercent = 0;
|
|
|
|
|
|
|
|
|
|
|
@ -93,7 +94,7 @@ class DataTransferIsolateController extends ChangeNotifier {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (message is String && message == 'done') {
|
|
|
|
if (message is String && message == 'done') {
|
|
|
|
running = false;
|
|
|
|
runningTest = 0;
|
|
|
|
_timer.stop();
|
|
|
|
_timer.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -103,25 +104,30 @@ class DataTransferIsolateController extends ChangeNotifier {
|
|
|
|
|
|
|
|
|
|
|
|
void generateOnSecondaryIsolate() {
|
|
|
|
void generateOnSecondaryIsolate() {
|
|
|
|
if (running) return;
|
|
|
|
if (running) return;
|
|
|
|
|
|
|
|
runningTest = 3;
|
|
|
|
running = true;
|
|
|
|
|
|
|
|
_timer.reset();
|
|
|
|
|
|
|
|
currentProgress.clear();
|
|
|
|
currentProgress.clear();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_timer = Stopwatch();
|
|
|
|
_timer.start();
|
|
|
|
_timer.start();
|
|
|
|
_newIceSP.send('start');
|
|
|
|
_newIceSP.send('start');
|
|
|
|
|
|
|
|
|
|
|
|
notifyListeners();
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> generateRandomNumbers() async {
|
|
|
|
Future<void> generateRandomNumbers(bool transferableTyped) async {
|
|
|
|
if (running) return;
|
|
|
|
if (running) return;
|
|
|
|
|
|
|
|
|
|
|
|
running = true;
|
|
|
|
if (transferableTyped) {
|
|
|
|
|
|
|
|
runningTest = 2;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
runningTest = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Random rng = Random();
|
|
|
|
Random rng = Random();
|
|
|
|
_timer = Stopwatch();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
currentProgress.clear();
|
|
|
|
currentProgress.clear();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_timer.reset();
|
|
|
|
_timer.start();
|
|
|
|
_timer.start();
|
|
|
|
|
|
|
|
|
|
|
|
List<int> randNums = [];
|
|
|
|
List<int> randNums = [];
|
|
|
@ -131,11 +137,18 @@ class DataTransferIsolateController extends ChangeNotifier {
|
|
|
|
for (int j = 0; j < 1000000; j++) {
|
|
|
|
for (int j = 0; j < 1000000; j++) {
|
|
|
|
randNums.add(rng.nextInt(100));
|
|
|
|
randNums.add(rng.nextInt(100));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await sendNumbers(randNums);
|
|
|
|
|
|
|
|
|
|
|
|
if (transferableTyped) {
|
|
|
|
|
|
|
|
final transferable =
|
|
|
|
|
|
|
|
TransferableTypedData.fromList([Int32List.fromList(randNums)]);
|
|
|
|
|
|
|
|
await sendNumbers(transferable);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
await sendNumbers(randNums);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> sendNumbers(List<int> numList) async {
|
|
|
|
Future<void> sendNumbers(dynamic numList) async {
|
|
|
|
return Future<void>(() {
|
|
|
|
return Future<void>(() {
|
|
|
|
_newIceSP.send(numList);
|
|
|
|
_newIceSP.send(numList);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -143,6 +156,8 @@ class DataTransferIsolateController extends ChangeNotifier {
|
|
|
|
|
|
|
|
|
|
|
|
Isolate get newIsolate => _newIsolate;
|
|
|
|
Isolate get newIsolate => _newIsolate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool get running => runningTest != 0;
|
|
|
|
|
|
|
|
|
|
|
|
void dispose() {
|
|
|
|
void dispose() {
|
|
|
|
super.dispose();
|
|
|
|
super.dispose();
|
|
|
|
_newIsolate?.kill(priority: Isolate.immediate);
|
|
|
|
_newIsolate?.kill(priority: Isolate.immediate);
|
|
|
@ -186,17 +201,26 @@ class RunningList extends StatelessWidget {
|
|
|
|
Future<void> _secondIsolateEntryPoint(SendPort callerSP) async {
|
|
|
|
Future<void> _secondIsolateEntryPoint(SendPort callerSP) async {
|
|
|
|
ReceivePort newIceRP = ReceivePort();
|
|
|
|
ReceivePort newIceRP = ReceivePort();
|
|
|
|
callerSP.send(newIceRP.sendPort);
|
|
|
|
callerSP.send(newIceRP.sendPort);
|
|
|
|
|
|
|
|
int length = 1;
|
|
|
|
|
|
|
|
|
|
|
|
newIceRP.listen(
|
|
|
|
newIceRP.listen(
|
|
|
|
(dynamic message) async {
|
|
|
|
(dynamic message) async {
|
|
|
|
if (message is String && message == 'start') {
|
|
|
|
if (message is String && message == 'start') {
|
|
|
|
await generateAndSum(callerSP, createNums());
|
|
|
|
await generateAndSum(callerSP, createNums(), length);
|
|
|
|
|
|
|
|
|
|
|
|
callerSP.send('done');
|
|
|
|
callerSP.send('done');
|
|
|
|
} else {
|
|
|
|
} else if (message is TransferableTypedData) {
|
|
|
|
await generateAndSum(callerSP, message as List<int>);
|
|
|
|
await generateAndSum(
|
|
|
|
|
|
|
|
callerSP, message.materialize().asInt32List(), length);
|
|
|
|
|
|
|
|
length++;
|
|
|
|
|
|
|
|
} else if (message is List<int>) {
|
|
|
|
|
|
|
|
await generateAndSum(callerSP, message, length);
|
|
|
|
|
|
|
|
length++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (length == 101) {
|
|
|
|
callerSP.send('done');
|
|
|
|
callerSP.send('done');
|
|
|
|
|
|
|
|
length = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -209,16 +233,17 @@ Iterable<int> createNums() sync* {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> generateAndSum(SendPort callerSP, Iterable<int> iter) async {
|
|
|
|
Future<void> generateAndSum(
|
|
|
|
|
|
|
|
SendPort callerSP, Iterable<int> iter, int length) async {
|
|
|
|
int sum = 0;
|
|
|
|
int sum = 0;
|
|
|
|
int count = 0;
|
|
|
|
int count = 1;
|
|
|
|
|
|
|
|
|
|
|
|
for (int x in iter) {
|
|
|
|
for (int x in iter) {
|
|
|
|
sum += x;
|
|
|
|
sum += x;
|
|
|
|
count++;
|
|
|
|
if (count % 1000000 == 0) {
|
|
|
|
if ((count + 1) % 1000000 == 0) {
|
|
|
|
callerSP.send((count ~/ 1000000) * length);
|
|
|
|
callerSP.send((count + 1) ~/ 1000000);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return sum;
|
|
|
|
return sum;
|
|
|
@ -235,11 +260,25 @@ Widget createButtons(BuildContext context) {
|
|
|
|
RaisedButton(
|
|
|
|
RaisedButton(
|
|
|
|
child: const Text('Transfer Data to 2nd Isolate'),
|
|
|
|
child: const Text('Transfer Data to 2nd Isolate'),
|
|
|
|
elevation: 8.0,
|
|
|
|
elevation: 8.0,
|
|
|
|
onPressed: controller.generateRandomNumbers,
|
|
|
|
color: (controller.runningTest == 1)
|
|
|
|
|
|
|
|
? Colors.blueAccent
|
|
|
|
|
|
|
|
: Colors.grey[300],
|
|
|
|
|
|
|
|
onPressed: () => controller.generateRandomNumbers(false),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
RaisedButton(
|
|
|
|
|
|
|
|
child: const Text('Transfer Data with TransferableTypedData'),
|
|
|
|
|
|
|
|
elevation: 8.0,
|
|
|
|
|
|
|
|
color: (controller.runningTest == 2)
|
|
|
|
|
|
|
|
? Colors.blueAccent
|
|
|
|
|
|
|
|
: Colors.grey[300],
|
|
|
|
|
|
|
|
onPressed: () => controller.generateRandomNumbers(true),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
RaisedButton(
|
|
|
|
RaisedButton(
|
|
|
|
child: const Text('Generate on 2nd Isolate'),
|
|
|
|
child: const Text('Generate on 2nd Isolate'),
|
|
|
|
elevation: 8.0,
|
|
|
|
elevation: 8.0,
|
|
|
|
|
|
|
|
color: (controller.runningTest == 3)
|
|
|
|
|
|
|
|
? Colors.blueAccent
|
|
|
|
|
|
|
|
: Colors.grey[300],
|
|
|
|
onPressed: controller.generateOnSecondaryIsolate,
|
|
|
|
onPressed: controller.generateOnSecondaryIsolate,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
],
|
|
|
|