kryo
ライブラリを使用して、オブジェクトのシリアライゼーションのパフォーマンスを向上させようとしています。java kryo 3.0.3オブジェクトのシリアライズ速度が遅い
私は、私はこの方法でそれをserilizingてる次のクラスに
public class CustomClass {
private String name;
private int[] array;
public CustomClass(String name, int size){
this.name = name;
fillArray(size);
}
private CustomClass(){ }
private void fillArray(int size){
array = new int[size];
Random random = new Random();
for (int i = 0; i < size; i++){
array[i] = random.nextInt();
}
}
}
を持っている私は、単一インスタンスのシリアライズ
public void kryoWrite(Object object){
Kryo kryo = new Kryo();
Output output = null;
try {
output = new Output(new FileOutputStream("kryo.txt"));
kryo.writeObject(output, object);
} catch (IOException e){
e.printStackTrace();
} finally {
if (output != null) {
output.close();
}
}
}
が、標準的なJavaのSerializable
を使用して、同じオブジェクトをシリアライズを作ってるんだ注意してくださいインターフェイスはより速く動作します。 たとえば、コンストラクタkryo
のシリアル化オブジェクトに1000000を渡した場合、188 msになります。Serializable
は、正確に同じオブジェクトを136 msにシリアル化します。
私は間違っているのです(私の曲のダブステップですか、笑)?これらの方法によって作成されserializaed 1000000のサイズを有するアレイの
EDIT
シリアル化は、適切
public static int[] getArray(int size){
int[] array = new int[size];
Random random = new Random();
for (int i = 0; i < size; i++){
array[i] = random.nextInt();
}
return array;
}
public static void kryoWriteArray(int[] array) throws FileNotFoundException {
Kryo kryo = new Kryo();
Output output = new Output(new FileOutputStream("array.txt"));
output.writeInts(array);
output.close();
}
139ミリ秒を要します。
毎回新しいインスタンスを作成するのではなく、 'Kryo'インスタンスを再利用しようとしましたか?あなたは各オブジェクトの代わりに配列全体を書き込むようにKryoに伝えましたか? –
@DarthAndroid私はCustomClassの1つのインスタンスをシリアル化していますが、kryoでint []配列を書き込もうとしましたが、もう一度perfomanceが低くなります –
@DarthAndroidこのインスタンスには文字列と1000000 –