Skip to content

Commit

Permalink
Update main.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
vztpv authored Aug 2, 2024
1 parent 7fcc505 commit 23f476f
Showing 1 changed file with 42 additions and 27 deletions.
69 changes: 42 additions & 27 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// with vztpv/scj3, claujson 0.23.1

// now, test only haswell..
// need C++14~, 64bit..
// mainly tested with C++17...
Expand All @@ -17,10 +17,10 @@
// using namespace std::literals::u8string_view_literals; // ??

void utf_8_test() {
using claujson::Value;
using claujson::_Value;

// C++17 - stringview, C++20~ - u8string_view
Value x(u8"こんにちは \\n wow hihi"sv); // no sv -> Data(bool)
_Value x(u8"こんにちは \\n wow hihi"sv); // no sv -> Data(bool)
if (x) { // if before string is not valid utf-8, then x is not valid. x -> false
auto& y = x.str_val();
std::cout << y.data() << "\n";
Expand All @@ -29,15 +29,15 @@ void utf_8_test() {

void key_dup_test() {
using claujson::Object;
using claujson::Value;
using claujson::_Value;
using claujson::Ptr;

Ptr<Object> x = Ptr<Object>(new Object());

x->add_object_element(Value("456"sv), Value(123));
x->add_object_element(Value("123"sv), Value(234));
x->add_object_element(Value("567"sv), Value(345));
x->add_object_element(Value("456"sv), Value(456));
x->add_object_element(_Value("456"sv), _Value(123));
x->add_object_element(_Value("123"sv), _Value(234));
x->add_object_element(_Value("567"sv), _Value(345));
x->add_object_element(_Value("456"sv), _Value(456));

uint64_t idx = 0;
bool found = false;
Expand All @@ -50,22 +50,22 @@ void key_dup_test() {
void str_test() {
auto x = u8"한글 Test";

claujson::Value A(x);
claujson::_Value A(x);

if (!A.is_str()) {
std::cout << "ERROR ";
}

auto y = "test";

claujson::Value B(y);
claujson::_Value B(y);

if (!B.is_str()) {
std::cout << "ERROR2 ";
}

std::string z = "test";
claujson::Value C(z);
claujson::_Value C(z);

if (!C.is_str()) {
std::cout << "ERROR3 ";
Expand Down Expand Up @@ -134,7 +134,7 @@ namespace claujson {
return *this;
}

JsonIterator& iterate(std::function<void(Value&)> func) {
JsonIterator& iterate(std::function<void(_Value&)> func) {
if (_m_now) {
size_t len = _m_now->get_data_size();
for (size_t i = _m_child_pos_in_parent.back(); i < len; ++i) {
Expand All @@ -148,11 +148,11 @@ namespace claujson {
return _m_now && _m_child_pos_in_parent.empty() == false && _m_child_pos_in_parent.back() < _m_now->get_data_size();
}

Value& now() {
_Value& now() {
if (_m_now) {
return _m_now->get_value_list(_m_child_pos_in_parent.back());
}
static Value null_data(nullptr, false);
static _Value null_data(nullptr, false);
return null_data;
}

Expand All @@ -168,9 +168,9 @@ namespace claujson {

int main(int argc, char* argv[])
{
std::cout << sizeof(std::vector<std::pair<claujson::Value, claujson::Value>>) << "\n";
std::cout << sizeof(std::vector<std::pair<claujson::_Value, claujson::_Value>>) << "\n";
//std::cout << sizeof(std::string) << " " << sizeof(claujson::Structured) << " " << sizeof(claujson::Array)
// << " " << sizeof(claujson::Object) << " " << sizeof(claujson::Value) << "\n";
// << " " << sizeof(claujson::Object) << " " << sizeof(claujson::_Value) << "\n";

if (argc <= 1) {
std::cout << "[program name] [json file name] (number of thread) \n";
Expand All @@ -180,15 +180,15 @@ int main(int argc, char* argv[])
diff_test();

/*
std::cout << sizeof(claujson::Value) << "\n";
std::cout << sizeof(claujson::_Value) << "\n";
std::cout << sizeof(claujson::Array) << "\n";
std::cout << sizeof(claujson::Object) << "\n";
{
auto str = R"()"sv;
claujson::init(0);
claujson::Value ut;
claujson::_Value ut;
std::cout << claujson::parse_str(str, ut, 1).first << "\n";
}
Expand All @@ -197,7 +197,7 @@ int main(int argc, char* argv[])
claujson::init(0);
claujson::Value ut;
claujson::_Value ut;
std::cout << claujson::parse_str(str, ut, 1).first << "\n";
}
Expand All @@ -206,7 +206,7 @@ int main(int argc, char* argv[])
claujson::init(0);
claujson::Value ut;
claujson::_Value ut;
std::cout << claujson::parse_str(str, ut, 1).first << "\n";
}
Expand Down Expand Up @@ -317,7 +317,7 @@ int main(int argc, char* argv[])
//

claujson::writer w;
w.write_parallel2("temp.json", j.Get(), thr_num, false);
w.write_parallel2("temp.json", j.Get(), thr_num, true);

std::cout << "write_parallel " << std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - b).count() << "ms\n";

Expand All @@ -333,7 +333,7 @@ int main(int argc, char* argv[])
claujson::Document _diff = claujson::diff(j.Get(), x.Get());

if (_diff.Get().is_valid() && _diff.Get().as_structured_ptr() && _diff.Get().as_array()->empty() == false) {
// return 1;
std::cout << "diff \n";//return 1;
}
}

Expand All @@ -359,12 +359,12 @@ int main(int argc, char* argv[])
int counter = 0;
ok = x.first;

std::vector<claujson::Value> vec;
std::vector<claujson::_Value> vec;

// json_pointer, json_pointerA <- u8string_view?

static const auto& _geometry = claujson::Value("geometry"sv);
static const auto& _coordinates = claujson::Value("coordinates"sv);
static const auto _geometry = claujson::_Value("geometry"sv);
static const auto _coordinates = claujson::_Value("coordinates"sv);

double sum = 0;
if (true && ok) {
Expand Down Expand Up @@ -435,8 +435,8 @@ int main(int argc, char* argv[])

std::cout << "\nwrite " << dur.count() << "ms\n";

claujson::Value X("geometry"sv); // in here, utf_8, unicode(\uxxxx) are checked..
claujson::Value Y("coordinates"sv); // use claujson::Value.
claujson::_Value X("geometry"sv); // in here, utf_8, unicode(\uxxxx) are checked..
claujson::_Value Y("coordinates"sv); // use claujson::_Value.

sum = 0; counter = 0;
/*if (true && ok) {
Expand Down Expand Up @@ -518,3 +518,18 @@ int main(int argc, char* argv[])

return 0;
}

/* result.
simdjson 236ms
[INFO] simdjson - stage1 start
[INFO] 83ms
[INFO] valid1 0ms
[INFO] test time 7ms
[INFO] 7ms
[INFO] parse1 42ms
[INFO] test6[INFO] parse2 4ms
[INFO] chk 0ms
[INFO] 46ms
[INFO] 138ms
total 139ms */

0 comments on commit 23f476f

Please sign in to comment.