Kryo序列化和ProroStruff序列化性能比较

本文对比了Kryo和Protobuf在JavaBean类的序列化和反序列化性能。测试结果显示,当对象数量较小(如10000左右)时,Kryo序列化速度更快;但当对象数量达到100000时,Protobuf的性能超越Kryo。在反序列化方面,无论对象数量多少,Protobuf始终优于Kryo。此外,Kryo序列化的数据大小也小于Protobuf。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

JavaBean类

package SeriazleCompare;

/**
 * Created by yang on 16-12-13.
 */
public class Student {
   
    private String name;
    private int age;
    private int time;
    private String xupt;

    public Student(){

    }
    public Student(String name, int age, int time, String xupt) {
        this.name = name;
        this.age = age;
        this.time = time;
        this.xupt = xupt;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", time=" + time +
                ", xupt='" + xupt + '\'' +
                '}';
    }
}
KryoSerialization序列化
package SeriazleCompare;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.Registration;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;


/**
 * Created by yang on 16-11-22.
 */
public class KryoSerialization {
   
    private Kryo kryo;
    private Registration registration = null;
    private Class<?> t;
    public KryoSerialization(){
        kryo = new Kryo();
        kryo.setReferences(true);
    }
    public void register(Cl
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值