How efficient is java serialization?

We have a class named row, which represents a row in the result set We need to write a list < < row > submission file so that we can retrieve it later

One way is to use Java's serialization support

I think the best way is to implement serialization in the row class Then we will use the serialize method of list < row > to write to the file

I wonder how efficient this will be? Will it take more space than just writing a CSV file adapter that converts our list < row >? Object is CSV file?

Solution

It depends on the type of row and the size and other aspects of the data you want to save. 1

On the one hand, the Java serialization protocol includes metadata for each class mentioned in serialization This requires a lot of space

on the other hand:

>Java serialization contains only metadata that is serialized once per Therefore, if a large number of instances of the same class are serialized, the metadata cost becomes irrelevant. > In a CSV file, all non text data must be converted to text In some cases (for example, large numbers, floating point numbers, Boolean values), the textual representation will be larger than the binary representation used in Java serialization

1 - for example, an array of random numbers and an array of zeros and 1 In the first case, Java serialization is better, while in the second case, CSV is better

But I think you may focus on the wrong things here:

>Unless you generate a large file, the size may not matter Disk space is cheap. > In either case, the file may be compressible, and the less dense form may be more compressible. > More importantly, whether the expression is suitable for the purpose; for example

>Do you want it to be human readable? > Do you want non Java programs (including shell scripts) to be able to read it? > Do you need to worry that changes in Java code will introduce class and serialization versions? > Do you want to be able to stream data? (when writing or reading.)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>