Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the efficiency about them? #142

Open
Darwinnpos opened this issue Jul 20, 2023 · 6 comments
Open

the efficiency about them? #142

Darwinnpos opened this issue Jul 20, 2023 · 6 comments

Comments

@Darwinnpos
Copy link

std::vector<std::vector<std::vector>> a; //ervery vector have n size
std::vector> b; //vector have n ^ 3 size
the efficiency about them?

@Darwinnpos
Copy link
Author

Darwinnpos commented Jul 20, 2023

my code and why?

#pragma warning(disable:4996)
#include <iostream>
#include <vector>
#include <yas/serialize.hpp>
#include <yas/std_types.hpp>

int main()
{
	std::vector<int> vData1;
	std::vector<std::vector<std::vector<int>>> vData2;
	for (int i{ 0 }; i < 1000000; i++)
	{
		vData1.push_back(i);
	}
	for (int i{ 0 }; i < 100; i++)
	{
		std::vector<std::vector<int>> a;
		for (int j{ 0 }; j < 100; j++)
		{
			std::vector<int> b;
			for (int k{ 0 }; k < 100; k++)
			{
				b.push_back(rand());
			}
			//std::cout << " b size" << b.size() << std::endl;
			a.push_back(b);
		}
		//std::cout << " a size" << a.size() << std::endl;
		vData2.push_back(a);
	}
	//std::cout << " vData2 size" << vData2.size() << std::endl;
	// 序列化
	constexpr std::size_t flags =
		yas::mem // IO type
		| yas::binary; // IO format
	std::cout << "==============TEST START===============\n\n";

	for (int i{ 0 }; i < 1; i++)
	{

		auto start = std::chrono::high_resolution_clock::now();

		auto buf = yas::save<flags>(
			YAS_OBJECT("myobject", vData1)
		);
		yas::load<flags>(buf,
			YAS_OBJECT_NVP("myobject"
				, ("a", vData1)
			)
		);
		auto end = std::chrono::high_resolution_clock::now();

		std::cout << "data type std::vector<int> size=1000 000\n";
		std::cout << "yas time cost: " << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() / 1000.0 << " ms\n";
		std::cout << "yas data size: " << buf.size/1000000.0 << " M byte\n\n";
		// 反序列化
		start = std::chrono::high_resolution_clock::now();
		auto buf2 = yas::save<flags>(
			YAS_OBJECT("myobject", vData2)
		);
		yas::load<flags>(buf2,
			YAS_OBJECT_NVP("myobject"
				, ("a", vData2)
			)
		);
		end = std::chrono::high_resolution_clock::now();
		std::cout << "data type std::vector<std::vector<std::vector<int>>> size=100 * 100 * 100\n";
		std::cout << "time cost: " << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() / 1000.0 << " ms\n";
		std::cout << "yas data size: " << buf2.size / 1000000.0 << " M byte\n\n";
	}

	std::cout << "==============TEST END===============\n";
	std::cout << "Hello World!\n";
}

@Darwinnpos
Copy link
Author

==============TEST START===============

data type std::vector size=1000 000
yas time cost: 6.962 ms
yas data size: 4.00002 M byte

data type std::vector<std::vector<std::vector>> size=100 * 100 * 100
time cost: 50.75 ms
yas data size: 4.08082 M byte

==============TEST END===============
Hello World!

@niXman
Copy link
Owner

niXman commented Jul 21, 2023

hmm... will look at this...

@niXman
Copy link
Owner

niXman commented Jul 24, 2023

@Darwinnpos I can't confirm that.

the results for me:

==============TEST START===============

data type std::vector<int> size=1000 000
yas time cost: 1.188 ms
yas data size: 4.00002 M byte

data type std::vector<std::vector<std::vector<int>>> size=100 * 100 * 100
time cost: 2.728 ms
yas data size: 4.08082 M byte

==============TEST END===============
Hello World!

compiled with -std=c++14 -O2

@Darwinnpos
Copy link
Author

I mean why the time cost is different?

@niXman
Copy link
Owner

niXman commented Oct 2, 2023

I mean why the time cost is different?

ah, got it.
will look at that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants