Beispiel #1
0
void test_object(T& t)
{
	Serializer sr;
	sr.Serialize(t, "test");
	std::cout << sr.GetString() << std::endl;

	DeSerializer dr;
	dr.Parse(sr.GetString());
	T de_t;
	dr.Deserialize(de_t, "test");
}
Beispiel #2
0
void test_map( T& map)
{
	Serializer sr;
	sr.Serialize(map, "test");
	std::cout << sr.GetString() << std::endl;

	DeSerializer dr;
	dr.Parse(sr.GetString());
	T de_map;
	dr.Deserialize(de_map, "test");
}
Beispiel #3
0
void test_array( T& arr)
{
	Serializer sr;
	sr.Serialize(arr, "test");
	std::cout << sr.GetString() << std::endl;

	DeSerializer dr;
	dr.Parse(sr.GetString());
	T de_arr;
	dr.Deserialize(de_arr, "test");
}
Beispiel #4
0
void test()
{
	Serializer sr;
	DeSerializer dr;

	auto tp = std::make_tuple(10, 12, string("test"));
	sr.Serialize(tp, "tuple");
	dr.Parse(sr.GetString());
	std::tuple<int, int, string> p;
	dr.Deserialize(p, "tuple");
}
Beispiel #5
0
void Performance()
{
	Serializer sr;
	DeSerializer dr;
	
	auto tp = std::make_tuple(10, 12, string("test"));
	Timer t;
	for (size_t i = 0; i < 10000; i++)
	{
		sr.Serialize(tp, "tuple");
		dr.Parse(sr.GetString());
		std::tuple<int, int, string> p;
		dr.Deserialize(p, "tuple");
	}

	int64_t elapsed = t.elapsed();
	cout << "kapok: " << elapsed <<"ms"<< endl;
}
Beispiel #6
0
void Performance_cmp()
{
    time_call("kapok all", []
    {
        Serializer sr;
        DeSerializer dr;
        Person tp = { 18, "bb", "aa" };
        Person p;
        for (size_t i = 0; i < 200000; i++)
        {
            sr.Serialize(tp, "tuple");
            dr.Parse(sr.GetString());
            dr.Deserialize(p, "tuple");
        }
    });
    time_call("kapok all2", []
    {
        for (size_t i = 0; i < 200000; i++)
        {
            Person tp = { 18, "bb", "aa" };
            Serializer sr;
            DeSerializer dr;
            sr.Serialize(tp, "tuple");
            dr.Parse(sr.GetString());
            Person p;
            dr.Deserialize(p, "tuple");
        }
    });
    time_call("msgpack all", []
    {
        Person src = { 18, "bb", "aa" };
        Person dst;
        msgpack::unpacked result;
        for (size_t i = 0; i < 200000; i++)
        {
            msgpack::sbuffer buffer;
            msgpack::pack(buffer, src);
            msgpack::unpack(result, buffer.data(), buffer.size());
            result.get().convert(&dst);
        }
    });
    time_call("msgpack all2", []
    {
        for (size_t i = 0; i < 200000; i++)
        {
            Person src = { 18, "bb", "aa" };
            std::stringstream buffer;
            msgpack::pack(buffer, src);
            buffer.seekg(0);
            std::string str(buffer.str());
            msgpack::unpacked result;
            msgpack::unpack(result, str.data(), str.size());
            msgpack::object deserialized = result.get();
            Person dst;
            deserialized.convert(&dst);
        }
    });
}
Beispiel #7
0
void Performance_kapok()
{
    time_call("kapok all", []
    {
        Serializer sr;
        DeSerializer dr;
        Person tp = { 18, "bb", "aa" };
        for (size_t i = 0; i < 100000; i++)
        {
            sr.Serialize(tp, "tuple");
            dr.Parse(sr.GetString());
            Person p;
            dr.Deserialize(p, "tuple");
        }
    });
    time_call("kapok all2", []
    {
        Person tp = { 18, "bb", "aa" };
        for (size_t i = 0; i < 100000; i++)
        {
            Serializer sr;
            DeSerializer dr;
            sr.Serialize(tp, "tuple");
            dr.Parse(sr.GetString());
            Person p;
            dr.Deserialize(p, "tuple");
        }
    });

    time_call("kapok Serializer", []
    {
        Serializer sr;
        Person tp = { 18, "bb", "aa" };
        for (size_t i = 0; i < 100000; i++)
        {
            sr.Serialize(tp, "tuple");
        }
    });
    time_call("kapok Serializer2", []
    {
        Person tp = { 18, "bb", "aa" };
        for (size_t i = 0; i < 100000; i++)
        {
            Serializer sr;
            sr.Serialize(tp, "tuple");
        }
    });

    Serializer sr;
    Person tp = { 18, "bb", "aa" };
    sr.Serialize(tp, "tuple");
    time_call("kapok DeSerializer", [&]
    {
        DeSerializer dr;
        for (size_t i = 0; i < 100000; i++)
        {
            dr.Parse(sr.GetString());
            Person p;
            dr.Deserialize(p, "tuple");
        }
    });
    time_call("kapok DeSerializer", [&]
    {
        for (size_t i = 0; i < 100000; i++)
        {
            DeSerializer dr;
            dr.Parse(sr.GetString());
            Person p;
            dr.Deserialize(p, "tuple");
        }
    });
}