-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathffibenchmark.dart
52 lines (41 loc) · 1.85 KB
/
ffibenchmark.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import 'dart:developer' as developer;
import 'dart:ffi' as ffi;
import 'dart:io' show Platform, Directory;
import 'package:benchmarking/benchmarking.dart';
import 'package:path/path.dart' as path;
import 'lib/http-server/http_server.dart';
import 'lib/nbody/nbody.dart';
import 'lib/spectral-norm/spectral_norm.dart';
typedef run_func = ffi.Void Function();
typedef Run = void Function();
main(List<String> arguments) async {
final hello_lib =
ffi.DynamicLibrary.open(path.join(Directory.current.path, "nbody.dll"));
final Run hello =
hello_lib.lookup<ffi.NativeFunction<run_func>>('run').asFunction();
final http_lib = ffi.DynamicLibrary.open(
path.join(Directory.current.path, "libhttp-server.dll"));
final Run http =
http_lib.lookup<ffi.NativeFunction<run_func>>('run').asFunction();
final spectral_lib = ffi.DynamicLibrary.open(
path.join(Directory.current.path, "spectral-norm.dll"));
final Run spectral =
spectral_lib.lookup<ffi.NativeFunction<run_func>>('run').asFunction();
devToolsPostEvent("Dart nbody", {'start': true});
syncBenchmark('Dart nbody', () => nbodyRun()).report();
devToolsPostEvent("Dart nbody", {'start': false});
devToolsPostEvent("C nbody", {'start': true});
syncBenchmark('C nbody', () => hello()).report();
devToolsPostEvent("C nbody", {'start': true});
(await asyncBenchmark('Dart HTTP Server', () async => await httpServerRun(),
settings: BenchmarkSettings(
minimumRunTime: Duration(milliseconds: 500),
)))
.report();
syncBenchmark('C http-server', () => http()).report();
syncBenchmark('Dart spectral-norm', () => spectralRun()).report();
syncBenchmark('C spectral-norm', () => spectral()).report();
}
void devToolsPostEvent(String eventName, Map<String, Object> eventData) {
developer.postEvent('DevTools.Event_$eventName', eventData);
}