/* * 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. */ #pragma once #include #include #include #include #include #include // template specifications for thrift struct template <> inline thrift::benchmark::Empty create() { return thrift::benchmark::Empty(); } template <> inline thrift::benchmark::OpEmpty create() { return thrift::benchmark::OpEmpty(); } template <> inline thrift::benchmark::SmallInt create() { thrift::benchmark::SmallInt d; d.smallint() = 5; return d; } template <> inline thrift::benchmark::OpSmallInt create() { thrift::benchmark::OpSmallInt d; d.smallint() = 5; return d; } template <> inline thrift::benchmark::BigInt create() { thrift::benchmark::BigInt d; d.bigint() = 0x1234567890abcdefL; return d; } template <> inline thrift::benchmark::OpBigInt create() { thrift::benchmark::OpBigInt d; d.bigint() = 0x1234567890abcdefL; return d; } template <> inline thrift::benchmark::SmallString create() { thrift::benchmark::SmallString d; d.str() = "small string"; return d; } template <> inline thrift::benchmark::OpSmallString create() { thrift::benchmark::OpSmallString d; d.str() = "small string"; return d; } template <> inline thrift::benchmark::BigString create() { thrift::benchmark::BigString d; d.str() = std::string(10'000, 'a'); return d; } template <> inline thrift::benchmark::OpBigString create() { thrift::benchmark::OpBigString d; d.str() = std::string(10'000, 'a'); return d; } template <> inline thrift::benchmark::BigBinary create() { auto buf = folly::IOBuf::create(10'000); buf->append(10'000); thrift::benchmark::BigBinary d; d.bin() = std::move(buf); return d; } template <> inline thrift::benchmark::LargeBinary create() { auto buf = folly::IOBuf::create(10'000'000); buf->append(10'000'000); thrift::benchmark::LargeBinary d; d.bin() = std::move(buf); return d; } template <> inline thrift::benchmark::Mixed create() { thrift::benchmark::Mixed d; d.int32() = 5; d.int64() = 12345; d.b() = true; d.str() = "hellohellohellohello"; return d; } template <> inline thrift::benchmark::OpMixed create() { thrift::benchmark::OpMixed d; d.int32() = 5; d.int64() = 12345; d.b() = true; d.str() = "hellohellohellohello"; return d; } template inline T createList(int size) { std::mt19937 rng; T d; while (size-- != 0) { d.lst()->push_back(rng()); } return d; } template <> inline thrift::benchmark::SmallListInt create() { return createList(10); } template <> inline thrift::benchmark::OpSmallListInt create() { return createList(10); } template <> inline thrift::benchmark::BigListInt create() { return createList(10000); } template <> inline thrift::benchmark::OpBigListInt create() { return createList(10000); } template <> inline thrift::benchmark::BigListMixed create() { std::vector vec( 10'000, create()); thrift::benchmark::BigListMixed d; d.lst() = std::move(vec); return d; } template <> inline thrift::benchmark::OpBigListMixed create() { std::vector vec( 10'000, create()); thrift::benchmark::OpBigListMixed d; d.lst() = std::move(vec); return d; } template <> inline thrift::benchmark::LargeListMixed create() { std::vector vec( 1'000'000, create()); thrift::benchmark::LargeListMixed d; d.lst() = std::move(vec); return d; } template <> inline thrift::benchmark::OpLargeListMixed create() { std::vector vec( 1'000'000, create()); thrift::benchmark::OpLargeListMixed d; d.lst() = std::move(vec); return d; } template inline T createSet(int size) { std::mt19937 rng; T d; while (size-- != 0) { d.s()->insert(rng()); } return d; } template <> inline thrift::benchmark::LargeSetInt create() { return createSet(1000000); } template <> inline thrift::benchmark::OpLargeSetInt create() { return createSet(1000000); } template <> inline thrift::benchmark::UnorderedSetInt create() { return createSet(1000000); } template <> inline thrift::benchmark::OpUnorderedSetInt create() { return createSet(1000000); } template <> inline thrift::benchmark::SortedVecSetInt create() { return createSet(1000000); } template <> inline thrift::benchmark::OpSortedVecSetInt create() { return createSet(1000000); } template inline T createMap(int size) { std::mt19937 rng; T d; while (size-- != 0) { d.m()[size] = rng(); } return d; } template inline T createMapMixed(int size) { T d; for (int i = 0; i < size; i++) { d.m()[i] = create(); } return d; } template <> inline thrift::benchmark::LargeMapInt create() { return createMap(1000000); } template <> inline thrift::benchmark::OpLargeMapInt create() { return createMap(1000000); } template <> inline thrift::benchmark::LargeMapMixed create() { return createMapMixed(1000000); } template <> inline thrift::benchmark::OpLargeMapMixed create() { return createMapMixed(1000000); } template <> inline thrift::benchmark::LargeUnorderedMapMixed create() { return createMapMixed(1000000); } template <> inline thrift::benchmark::OpLargeUnorderedMapMixed create() { return createMapMixed(1000000); } template <> inline thrift::benchmark::LargeSortedVecMapMixed create() { return createMapMixed(1000000); } template <> inline thrift::benchmark::OpLargeSortedVecMapMixed create() { return createMapMixed(1000000); } template <> inline thrift::benchmark::UnorderedMapInt create() { return createMap(1000000); } template <> inline thrift::benchmark::OpUnorderedMapInt create() { return createMap(1000000); } template <> inline thrift::benchmark::NestedMapRaw create() { thrift::benchmark::NestedMapRaw map; populateMap([&](int i, int j, int k, int l, int m, int v) { map.m()[i][j][k][l][m] = v; }); return map; } template <> inline thrift::benchmark::SortedVecNestedMapRaw create() { thrift::benchmark::SortedVecNestedMapRaw map; populateMap([&](int i, int j, int k, int l, int m, int v) { map.m()[i][j][k][l][m] = v; }); return map; } template inline T createNestedMap() { T d; populateMap([&](int i, int j, int k, int l, int m, int v) { d.m()[i].m()[j].m()[k].m()[l].m()[m] = v; }); return d; } template <> inline thrift::benchmark::NestedMap create() { return createNestedMap(); } template <> inline thrift::benchmark::OpNestedMap create() { return createNestedMap(); } template <> inline thrift::benchmark::SortedVecNestedMap create() { return createNestedMap(); } template <> inline thrift::benchmark::OpSortedVecNestedMap create() { return createNestedMap(); } template inline T createLargeMixed() { T d; d.var1() = 5; d.var2() = 12345; d.var3() = true; d.var4() = "hello"; d.var5() = 5; d.var6() = 12345; d.var7() = true; d.var8() = "hello"; d.var9() = 5; d.var10() = 12345; d.var11() = true; d.var12() = "hello"; d.var13() = 5; d.var14() = 12345; d.var15() = true; d.var16() = "hello"; d.var17() = 5; d.var18() = 12345; d.var19() = true; d.var20() = "hello"; d.var21() = 5; d.var22() = 12345; d.var23() = true; d.var24() = "hello"; d.var25() = 5; d.var26() = 12345; d.var27() = true; d.var28() = "hello"; d.var29() = 5; d.var30() = 12345; d.var31() = true; d.var32() = "hello"; d.var33() = 5; d.var34() = 12345; d.var35() = true; d.var36() = "hello"; d.var37() = 5; d.var38() = 12345; d.var39() = true; d.var40() = "hello"; d.var41() = 5; d.var42() = 12345; d.var43() = true; d.var44() = "hello"; d.var45() = 5; d.var46() = 12345; d.var47() = true; d.var48() = "hello"; d.var49() = 5; d.var50() = 12345; d.var51() = true; d.var52() = "hello"; d.var53() = 5; d.var54() = 12345; d.var55() = true; d.var56() = "hello"; d.var57() = 5; d.var58() = 12345; d.var59() = true; d.var60() = "hello"; d.var61() = 5; d.var62() = 12345; d.var63() = true; d.var64() = "hello"; d.var65() = 5; d.var66() = 12345; d.var67() = true; d.var68() = "hello"; d.var69() = 5; d.var70() = 12345; d.var71() = true; d.var72() = "hello"; d.var73() = 5; d.var74() = 12345; d.var75() = true; d.var76() = "hello"; d.var77() = 5; d.var78() = 12345; d.var79() = true; d.var80() = "hello"; d.var81() = 5; d.var82() = 12345; d.var83() = true; d.var84() = "hello"; d.var85() = 5; d.var86() = 12345; d.var87() = true; d.var88() = "hello"; d.var89() = 5; d.var90() = 12345; d.var91() = true; d.var92() = "hello"; d.var93() = 5; d.var94() = 12345; d.var95() = true; d.var96() = "hello"; d.var97() = 5; d.var98() = 12345; d.var99() = true; d.var100() = "hello"; return d; } template <> inline thrift::benchmark::LargeMixed create() { return createLargeMixed(); } template <> inline thrift::benchmark::OpLargeMixed create() { thrift::benchmark::OpLargeMixed d; return createLargeMixed(); } template inline T createMixedInt() { std::mt19937 rng; T d; d.var1() = rng(); d.var2() = rng(); d.var3() = rng(); d.var4() = rng(); d.var5() = rng(); d.var6() = rng(); d.var7() = rng(); d.var8() = rng(); d.var9() = rng(); d.varx() = rng(); d.vary() = rng(); d.varz() = rng(); return d; } template <> inline thrift::benchmark::MixedInt create() { return createMixedInt(); } template <> inline thrift::benchmark::OpMixedInt create() { return createMixedInt(); } template <> inline thrift::benchmark::BigListMixedInt create() { std::vector vec( 10'000, create()); thrift::benchmark::BigListMixedInt d; d.lst() = std::move(vec); return d; } template <> inline thrift::benchmark::OpBigListMixedInt create() { std::vector vec( 10'000, create()); thrift::benchmark::OpBigListMixedInt d; d.lst() = std::move(vec); return d; } template <> inline thrift::benchmark::ComplexStruct create() { thrift::benchmark::ComplexStruct d; d.var1() = create(); d.var2() = create(); d.var3() = create(); d.var4() = create(); d.var5() = create(); d.var6() = create(); d.var7() = create(); d.var8() = create(); d.var9() = create(); d.var10() = create(); d.var11() = create(); d.var12() = create(); return d; } template <> inline thrift::benchmark::OpComplexStruct create() { thrift::benchmark::OpComplexStruct d; d.var1() = create(); d.var2() = create(); d.var3() = create(); d.var4() = create(); d.var5() = create(); d.var6() = create(); d.var7() = create(); d.var8() = create(); d.var9() = create(); d.var10() = create(); d.var11() = create(); d.var12() = create(); return d; }