-
Notifications
You must be signed in to change notification settings - Fork 98
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
Comments
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";
} |
==============TEST START=============== data type std::vector size=1000 000 data type std::vector<std::vector<std::vector>> size=100 * 100 * 100 ==============TEST END=============== |
hmm... will look at this... |
@Darwinnpos I can't confirm that. the results for me:
compiled with |
I mean why the time cost is different? |
ah, got it. |
std::vector<std::vector<std::vector>> a; //ervery vector have n size
std::vector> b; //vector have n ^ 3 size
the efficiency about them?
The text was updated successfully, but these errors were encountered: