platform/experiment/performance/bin/main.dart

105 lines
2.7 KiB
Dart
Raw Normal View History

2021-12-30 02:07:04 +00:00
import 'dart:isolate';
import 'package:http/http.dart' as http;
Future<void> fortunes(var message) async {
var stopwatch = Stopwatch()..start();
2022-09-18 16:58:28 +00:00
var url = Uri.http('localhost:8080', '/fortunes');
2021-12-30 02:07:04 +00:00
var response = await http.get(url);
print('Execution($message) Time: ${stopwatch.elapsed.inMilliseconds}ms');
stopwatch.stop();
if (response.statusCode == 200) {
print('Execution($message): success');
} else {
print('Execution($message): error');
}
}
Future<void> plaintext(var message) async {
var stopwatch = Stopwatch()..start();
2022-09-18 16:58:28 +00:00
var url = Uri.http('localhost:8080', '/plaintext');
2021-12-30 02:07:04 +00:00
var response = await http.get(url);
if (response.statusCode == 200) {
2022-01-23 05:10:50 +00:00
print('Execution($message): ${response.body}.');
2021-12-30 02:07:04 +00:00
} else {
print('Execution($message): error');
}
print('Execution($message) Time: ${stopwatch.elapsed.inMilliseconds}ms');
stopwatch.stop();
}
Future<void> json(var message) async {
var stopwatch = Stopwatch()..start();
2022-09-18 16:58:28 +00:00
var url = Uri.http('localhost:8080', '/json');
2021-12-30 02:07:04 +00:00
var response = await http.get(url);
print('Execution($message) Time: ${stopwatch.elapsed.inMilliseconds}ms');
stopwatch.stop();
if (response.statusCode == 200) {
print('Execution($message): success');
} else {
print('Execution($message): error');
}
}
Future<void> dbUpdate(var message) async {
var stopwatch = Stopwatch()..start();
2022-09-18 16:58:28 +00:00
var url = Uri.http('localhost:8080', '/updates', {'queries': "5"});
2021-12-30 02:07:04 +00:00
var response = await http.get(url);
print('Execution($message) Time: ${stopwatch.elapsed.inMilliseconds}ms');
stopwatch.stop();
if (response.statusCode == 200) {
print('Execution($message): success');
} else {
print('Execution($message): error');
}
}
Future<void> dbSingleQuery(var message) async {
var stopwatch = Stopwatch()..start();
2022-09-18 16:58:28 +00:00
var url = Uri.http('localhost:8080', '/db');
2021-12-30 02:07:04 +00:00
var response = await http.get(url);
print('Execution($message) Time: ${stopwatch.elapsed.inMilliseconds}ms');
stopwatch.stop();
if (response.statusCode == 200) {
print('Execution($message): success');
} else {
print('Execution($message): error');
}
}
Future<void> dbMultipleQuery(var message) async {
var stopwatch = Stopwatch()..start();
2022-09-18 16:58:28 +00:00
var url = Uri.http('localhost:8080', '/query', {'queries': "5"});
2021-12-30 02:07:04 +00:00
var response = await http.get(url);
print('Execution($message) Time: ${stopwatch.elapsed.inMilliseconds}ms');
stopwatch.stop();
if (response.statusCode == 200) {
print('Execution($message): success');
} else {
print('Execution($message): error');
}
}
void main() async {
2022-09-18 16:58:28 +00:00
var concurrency = 2000;
2021-12-30 02:07:04 +00:00
for (var i = 0; i < concurrency; i++) {
2022-09-18 16:58:28 +00:00
Isolate.spawn(dbSingleQuery, 'Instance_$i');
2021-12-30 02:07:04 +00:00
}
await Future.delayed(const Duration(seconds: 10));
//print("Exit");
}