A
A
Alexander Alekseev2021-04-20 18:24:51
Android
Alexander Alekseev, 2021-04-20 18:24:51

Android C++ code is too slow. This is fine?

Hello! I'm starting to learn programming for Android using the OpenCV library. The speed of the Native code disappointed me. Manual enumeration of pixels works about 10 times slower than on the x86 processor. I included optimization in CMakeLists.txt, but I don't know if it was done correctly. Next, I measured the speed of the function:
cv::cvtColor(mat, gray, cv::COLOR_RGBA2GRAY);
It is also about 10 times behind.
And the Gaussian blur with a radius of 15 lags behind in speed by as much as 50 times:

cv::GaussianBlur(gray, gray_blurred, cv::Size(), 15.0);


I just recently started learning android programming and just tried the NDK yesterday, so a lot of things are unusual for me. Is it normal for smartphones to lag so far behind PCs? I expected that the slowdown would be 2-4 times, especially for Native, but not 50 times. There is a suspicion that the library on a PC actively uses vector instructions and, possibly, multithreading, while for some reason these features are not used on a smartphone by default, but this is unlikely. Now I'm just interested in the opinion of those who write in C ++ for android and PC.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Deiwan, 2021-04-20
@Deiwan

Android is just a weaker platform than Windows (or Linux), and the device itself has less RAM than a computer, so I assume that the problem is in the OS or RAM, and not in features

M
maaGames, 2021-04-21
@maaGames

1. the same source code on x86 and ARM can work with VERY different performance
2. java code as a whole can run faster than native C ++ if the time to call and convert data is longer than the time of the native function. Those. calls to native functions from Java code can degrade performance, not improve it.

O
Oleg, 2021-04-21
@402d

Android is tailored for the phone. The telephony service must work reliably. The rest is just a guest.
Even the program the user is currently interacting with can be killed at any moment.
The entire architecture of the android application is based on what the user is doing now. As soon as the window goes
under another, it is immediately transferred to the stopped state.
The possibilities of background processes in new versions were slaughtered to the very neck. Due to attempts to extend battery life, it is now almost impossible to do something that works in the background for a long time. And the processor resources are allocated according to the residual principle.

A
Alexander Alekseev, 2021-04-21
@ntllct

I found benchmarks for my processors. Such a gap in speed is not normal. Later I will study the problem in more detail.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question