[perf]java基本操作性能試験-反射
2252 ワード
性能テスト:
ソフトハードウェアとその複雑さのため、本結果はあくまでも参考になる。
コード:
https://github.com/zhang-xzhi/perftest
テスト方法:
1つのtestはloopを実行して、suiteのために、suiteの平均時間を計算します。
複数のスピッツを走らせて、それぞれのスピッツの平均時間を計算します。
全体平均時間は、それぞれのsuiteの平均時間から計算される。
それぞれのsuiteの平均時間と全体平均時間の誤差がデルタ内にあるかどうかを計算します。
満足するなら、今回のテストは有効です。
満足していない場合は、loopを増やして運転を再開します。
時間単位はnsです。
反射
loop=20000 suite=5 delta=0.2
S 1:
Reflection Constructor
ReflectionField
ReflectionMethod
class.getを使うためにコンストラクタ、Field、Methodのオブジェクトを得る。
2:
Reflection Contront Invoke
ReflectionFieldInvoke
ReflectionMethodInvoke
Costructor,Field,Methodオブジェクトを使用してオブジェクトを作成し,値を取って,メソッドを呼び出します。
S 3:
Reflection ConstructorDirectAccess
Reflection Field_DirectAccess
ReflectionMethodDirectAccess
javaコードを使って直接オブジェクトを作成し、値を取って、メソッドを呼び出します。
S 1:S 2:S 3はそれぞれ1桁ずつ違います。
ReflectionNewInstance
classの実現によってCostructorの対象をキャッシュしましたので、class.newInstanceの時間はReflection ControuctoInvokeより少し遅いです。
ソフトハードウェアとその複雑さのため、本結果はあくまでも参考になる。
コード:
https://github.com/zhang-xzhi/perftest
テスト方法:
1つのtestはloopを実行して、suiteのために、suiteの平均時間を計算します。
複数のスピッツを走らせて、それぞれのスピッツの平均時間を計算します。
全体平均時間は、それぞれのsuiteの平均時間から計算される。
それぞれのsuiteの平均時間と全体平均時間の誤差がデルタ内にあるかどうかを計算します。
満足するなら、今回のテストは有効です。
満足していない場合は、loopを増やして運転を再開します。
時間単位はnsです。
反射
loop=20000 suite=5 delta=0.2
avg=512 name=ReflectionConstructor des=class.getConstructor
avg=59 name=ReflectionConstructorInvoke des=constructor.newInstance
avg=8 name=ReflectionConstructor_DirectAccess des=direct access constructor.
avg=480 name=ReflectionField des=getDeclaredField and setAccessible.
avg=63 name=ReflectionFieldInvoke des=field.get().
avg=5 name=ReflectionField_DirectAccess des=direct access field.
avg=665 name=ReflectionMethod des=getDeclaredMethod and setAccessible.
avg=15 name=ReflectionMethodInvoke des=method.invoke().
avg=5 name=ReflectionMethod_DirectAccess des=direct access method.
avg=110 name=ReflectionNewInstance des=class.newInstance()
構造関数,方法,fieldの3つの動作方式を試験した。S 1:
Reflection Constructor
ReflectionField
ReflectionMethod
class.getを使うためにコンストラクタ、Field、Methodのオブジェクトを得る。
2:
Reflection Contront Invoke
ReflectionFieldInvoke
ReflectionMethodInvoke
Costructor,Field,Methodオブジェクトを使用してオブジェクトを作成し,値を取って,メソッドを呼び出します。
S 3:
Reflection ConstructorDirectAccess
Reflection Field_DirectAccess
ReflectionMethodDirectAccess
javaコードを使って直接オブジェクトを作成し、値を取って、メソッドを呼び出します。
S 1:S 2:S 3はそれぞれ1桁ずつ違います。
ReflectionNewInstance
classの実現によってCostructorの対象をキャッシュしましたので、class.newInstanceの時間はReflection ControuctoInvokeより少し遅いです。