| 25 | |
| 26 | Y_UNIT_TEST_SUITE(Json2Yson) { |
| 27 | Y_UNIT_TEST(NOAPACHE_REQUESTS) { |
| 28 | const ui32 warmUpRetries = 5; |
| 29 | const TVector<double> percentiles = {0.25, 0.5, 0.6, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 0.97, 0.99, 1.0}; |
| 30 | |
| 31 | NSimpleHistogram::TMultiHistogramCalcer<ui64> calcer; |
| 32 | |
| 33 | TString requests = GetRequestsWithDecoding(GetWorkPath() + "/noapache_requests_sample_lz4", NBlockCodecs::Codec("lz4")); |
| 34 | TStringInput inputStream(requests); |
| 35 | |
| 36 | for (TString jsonRequest, jsonString, ysonString; inputStream.ReadLine(jsonRequest);) { |
| 37 | TStringInput jsonInput(jsonRequest); |
| 38 | NJson::TJsonValue readedJson; |
| 39 | NJson::ReadJsonTree(&jsonInput, &readedJson, true); |
| 40 | jsonRequest.clear(); |
| 41 | |
| 42 | ui64 writeTime = Max<ui64>(); |
| 43 | ui64 readTime = Max<ui64>(); |
| 44 | |
| 45 | for (ui32 i = 0; i < warmUpRetries; ++i) { |
| 46 | NJson::TJsonValue Json2Json; |
| 47 | TStringOutput jsonWriteOutput(jsonString); |
| 48 | NJsonWriter::TBuf jsonBuf(NJsonWriter::HEM_UNSAFE, &jsonWriteOutput); |
| 49 | |
| 50 | writeTime = Min(writeTime, Run([&]() { |
| 51 | jsonBuf.WriteJsonValue(&readedJson); |
| 52 | })); |
| 53 | |
| 54 | TStringInput jsonInput(jsonString); |
| 55 | NJson::TJsonReaderConfig config; |
| 56 | config.DontValidateUtf8 = true; |
| 57 | readTime = Min(readTime, Run([&]() { |
| 58 | NJson::ReadJsonTree(&jsonInput, &config, &Json2Json, true); |
| 59 | })); |
| 60 | |
| 61 | UNIT_ASSERT_VALUES_EQUAL( |
| 62 | NJsonWriter::TBuf().WriteJsonValue(&readedJson, true).Str(), |
| 63 | NJsonWriter::TBuf().WriteJsonValue(&Json2Json, true).Str()); |
| 64 | |
| 65 | jsonString.clear(); |
| 66 | } |
| 67 | |
| 68 | calcer.RecordValue("read_json", readTime); |
| 69 | calcer.RecordValue("write_json", writeTime); |
| 70 | calcer.RecordValue("read_and_write_json", readTime + writeTime); |
| 71 | |
| 72 | writeTime = Max<ui64>(); |
| 73 | readTime = Max<ui64>(); |
| 74 | |
| 75 | for (ui32 i = 0; i < warmUpRetries; ++i) { |
| 76 | NJson::TJsonValue convertedJson; |
| 77 | TStringOutput ysonOutput(ysonString); |
| 78 | |
| 79 | writeTime = Min(writeTime, Run([&]() { |
| 80 | NJson2Yson::SerializeJsonValueAsYson(readedJson, &ysonOutput); |
| 81 | })); |
| 82 | |
| 83 | TStringInput ysonInput(ysonString); |
| 84 | readTime = Min(readTime, Run([&]() { |
nothing calls this directly
no test coverage detected