/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include namespace apache::thrift::test { template folly::IOBuf genListDouble() { Struct foo; foo.field3_ref().emplace(10'000, 1'000); return CompactSerializer::serialize(foo).moveAsValue(); } template folly::IOBuf genListI32() { Struct foo; foo.field4_ref().emplace(10'000, 1'000); return CompactSerializer::serialize(foo).moveAsValue(); } const folly::IOBuf kListDoubleWithIndex = genListDouble(); const folly::IOBuf kListDoubleWithoutIndex = genListDouble(); const folly::IOBuf kListI32WithIndex = genListI32(); const folly::IOBuf kListI32WithoutIndex = genListI32(); // We only need to disable checksum for list with index, since // `list` is cheap to skip, we won't compute its index and checksum. const folly::IOBuf kListI32WithIndexNoChecksum = genListI32(); BENCHMARK(list_double_with_index_eager) { CompactSerializer::deserialize(&kListDoubleWithIndex); } BENCHMARK_RELATIVE(list_double_with_index_lazy) { CompactSerializer::deserialize(&kListDoubleWithIndex); } BENCHMARK_RELATIVE(list_double_with_index_lazy_then_access_field) { CompactSerializer::deserialize(&kListDoubleWithIndex).field3_ref(); } BENCHMARK(list_i32_with_index_eager) { CompactSerializer::deserialize(&kListI32WithIndex); } BENCHMARK_RELATIVE(list_i32_with_index_lazy) { CompactSerializer::deserialize(&kListI32WithIndex); } BENCHMARK_RELATIVE(list_i32_with_index_lazy_without_checksum) { CompactSerializer::deserialize( &kListI32WithIndexNoChecksum); } BENCHMARK_RELATIVE(list_i32_with_index_lazy_then_access_field) { CompactSerializer::deserialize(&kListI32WithIndex).field4_ref(); } BENCHMARK_RELATIVE( list_i32_with_index_lazy_then_access_field_without_checksum) { CompactSerializer::deserialize( &kListI32WithIndexNoChecksum) .field4_ref(); } BENCHMARK(list_double_without_index_eager) { CompactSerializer::deserialize(&kListDoubleWithIndex); } BENCHMARK_RELATIVE(list_double_without_index_lazy) { CompactSerializer::deserialize(&kListDoubleWithIndex); } BENCHMARK_RELATIVE(list_double_without_index_lazy_then_access_field) { CompactSerializer::deserialize(&kListDoubleWithIndex).field3_ref(); } BENCHMARK(list_i32_without_index_eager) { CompactSerializer::deserialize(&kListI32WithIndex); } BENCHMARK_RELATIVE(list_i32_without_index_lazy) { CompactSerializer::deserialize(&kListI32WithIndex); } BENCHMARK_RELATIVE(list_i32_without_index_lazy_then_access_field) { CompactSerializer::deserialize(&kListI32WithIndex).field4_ref(); } } // namespace apache::thrift::test int main(int argc, char** argv) { folly::init(&argc, &argv); folly::runBenchmarks(); }