In the 21st century, the Dart compiler is so primitive that it cannot properly compile elementary code for which other compilers generate efficient code?
I am ashamed that I use Dart for computing.
Dart is completely unsuitable for this purpose.
Dart Pad results:
Time passed: 0.000, Test 'good': 2.399 ms
Time passed: 0.003, Test 'bad': 3.8 ms
Time passed: 0.006, Test 'good': 1.4 ms
Time passed: 0.008, Test 'bad': 2 ms
Time passed: 0.010, Test 'good': 1.5 ms
Time passed: 0.011, Test 'bad': 1.801 ms
Time passed: 0.013, Test 'good': 0.901 ms
Time passed: 0.014, Test 'bad': 0.901 ms
Time passed: 0.015, Test 'good': 0.899 ms
Time passed: 0.016, Test 'bad': 0.899 ms
Time passed: 0.017, Test 'good': 1 ms
Time passed: 0.018, Test 'bad': 0.9 ms
Dart VM results:
Time passed: 0.000, Test 'good': 1.731 ms
Time passed: 0.004, Test 'bad': 159.304 ms
Time passed: 0.163, Test 'good': 2.185 ms
Time passed: 0.166, Test 'bad': 156.398 ms
Time passed: 0.322, Test 'good': 0.614 ms
Time passed: 0.323, Test 'bad': 156.95 ms
Time passed: 0.480, Test 'good': 0.696 ms
Time passed: 0.481, Test 'bad': 157.634 ms
Time passed: 0.638, Test 'good': 0.687 ms
Time passed: 0.639, Test 'bad': 157.56 ms
Time passed: 0.797, Test 'good': 0.728 ms
Time passed: 0.798, Test 'bad': 157.279 ms
Source code:
void main() {
final count = 1000000;
final names = ['good', 'bad'];
final tests = [_test1, _test2];
final sw = Stopwatch();
var repeat = 150;
sw.start();
while (repeat-- > 0) {
for (var i = 0; i < tests.length; i++) {
final name = names[i];
final test = tests[i];
final seconds = (sw.elapsedMilliseconds / 1000).toStringAsFixed(3);
final title = 'Time passed: $seconds, Test \'$name\'';
_measure(title, 1, () => test(count));
}
}
}
void _measure(String name, int count, Function() f) {
final sw = Stopwatch();
sw.start();
for (var i = 0; i < count; i++) {
f();
}
sw.stop();
final time = sw.elapsedMicroseconds / 1000;
print('$name: $time ms');
}
int add(int x, int y) => x + y;
int add2(int Function(int x, int y) f, int x, int y) => f(x, y);
void _test1(int count) {
for (var i = 0; i < count; i++) {
add(1, 2);
add(1, 2);
add(1, 2);
add(1, 2);
add(1, 2);
add(1, 2);
add(1, 2);
add(1, 2);
add(1, 2);
add(1, 2);
}
}
void _test2(int count) {
for (var i = 0; i < count; i++) {
add2(add, 1, 2);
add2(add, 1, 2);
add2(add, 1, 2);
add2(add, 1, 2);
add2(add, 1, 2);
add2(add, 1, 2);
add2(add, 1, 2);
add2(add, 1, 2);
add2(add, 1, 2);
add2(add, 1, 2);
}
}
Rust programmers use this kind of computation all over the place. This is in case you want to say that this is not actual.
But Rust is not Javascript, but they are smart people too (Rust developers).
I am very surprised and cannot understand what the Dart developers are doing at work, while other developers are developing normal compilers for normal calculations.
Sorry to be rude, but how is this possible in 2021?
--
For more ways to connect visit https://dart.dev/community
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/5aefa980-54e3-4b39-8d0f-3361a2147a56n%40dartlang.org.