-
Notifications
You must be signed in to change notification settings - Fork 28.9k
Description
I was trying to benchmark the performance of flutter and compare it with that of Java and C. So I chose a simple function to calculate nth prime number.
The problem is that the time taken to calculate the 20000th prime number in release mode (821 ms) was almost 8 times slower than that in debug mode (106 ms).
The method that I used is given below:
int nThPrimeNumber(int n) {
int counter = 0;
for (var i = 1;; i++) {
if (isPrime(i)) counter++;
if (counter == n) {
return i;
}
}
}
bool isPrime(var n) {
if (n < 2) return false;
for (var i = 2; i * i <= n; i++) {
if (n % i == 0) return false;
}
return true;
}
Full source code and benchmark result is available in this repository.
I know this is not a big issue and there are some serious issues which needs to be resolved. But I am creating this issue because I found that in debug mode, Flutter code was running faster than C (but only in debug mode).
If this issue is fixed for release mode, some CPU intensive tasks such as image processing could be easily (and quickly too!) performed in Dart without having the need to write them in C/C++.