JNA library slower screenshot than robot class?

大兔子大兔子 提交于 2019-11-30 18:33:00

JNA calls take much time, instead JNI uses c++ directly.

Don't try to optimise too early. Create a sensible interface to get the data you want (A screenshot) then create the implementation you want based on either Robot, JNA or JNI.

I would guess that the different implementations give completely different results based on the environment that it is running.

Rule One of Programming: First make it work. Then profile, find a bottleneck and remove or mitigate the effect of the bottleneck.

First, check if the native library is actually faster than your code. It might not be the case.

Assuming you already did check that, I would say the problem here is that calls with JNA are really slow. To skip the one call per cycle problem I would suggest writing a C function like this:

    void callWithJNAfunction(int rectPosX, int rectPosY, rectSideX, rectSideY,int numberOfCycles) {
    for (int i = 0; i < numberOfCycles; i++) {
        //code in C that calls the library
    }

Now compile this code and call the callWithJNAfunction(...) with JNA.

If the problem is the slowness of the JNA calls, it will get faster.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!