Android Java アプリケーションと Android NDK アプリケーションのパフォーマンスの違いに取り組んでいます。3D グラフィックスの例として、90000 を超える頂点に対して Matrix4D-Vector4D 変換を実行しました。
Java バージョンはC バージョンよりも100 倍近く遅いようです。私は何か間違っていましたか?似たような経験をした人はいますか?
変換のための私のJavaコード:
long t1 = System.nanoTime();
for ( int i = 0; i < vCount; i++)
{
Vector4 vOut = new Vector4();
Vector4 v = vertices[i];
vOut.v_[0] = v.v_[0] * matrix[0].v_[0];
vOut.v_[1] = v.v_[0] * matrix[0].v_[1];
vOut.v_[2] = v.v_[0] * matrix[0].v_[2];
vOut.v_[3] = v.v_[0] * matrix[0].v_[3];
vOut.v_[0] += v.v_[1] * matrix[1].v_[0];
vOut.v_[1] += v.v_[1] * matrix[1].v_[1];
vOut.v_[2] += v.v_[1] * matrix[1].v_[2];
vOut.v_[3] += v.v_[1] * matrix[1].v_[3];
vOut.v_[0] += v.v_[2] * matrix[2].v_[0];
vOut.v_[1] += v.v_[2] * matrix[2].v_[1];
vOut.v_[2] += v.v_[2] * matrix[2].v_[2];
vOut.v_[3] += v.v_[2] * matrix[2].v_[3];
vOut.v_[0] += v.v_[3] * matrix[3].v_[0];
vOut.v_[1] += v.v_[3] * matrix[3].v_[1];
vOut.v_[2] += v.v_[3] * matrix[3].v_[2];
vOut.v_[3] += v.v_[3] * matrix[3].v_[3];
vertices[i] = vOut;
}
long t2 = System.nanoTime();
long diff = t2 - t1;
double ms = (double)(diff / 1000000.0f);
Log.w("GL2JNIView", String.format("ms %.2f ", ms));
パフォーマンス (変換 > 90,000 頂点 | Android 4.0.4 SGS II): (200 回の実行の中央値)
JAVA-Version: 2 FPS
C-Version: 190 FPS