MCPcopy Create free account
hub / github.com/apache/fory / createBenchmarkCase

Function createBenchmarkCase

benchmarks/javascript/benchmark.js:902–950  ·  view source on GitHub ↗
(serializerName, dataset, operation)

Source from the content-addressed store, hash-verified

900}
901
902function createBenchmarkCase(serializerName, dataset, operation) {
903 const value = dataset.createValue();
904
905 if (serializerName === "fory") {
906 const foryValue = normalizeForyValue(dataset.key, value);
907 if (operation === "Serialize") {
908 return () => {
909 const bytes = dataset.foryWriter.serialize(foryValue);
910 blackhole ^= bytes.length;
911 };
912 }
913 const bytes = dataset.foryWriter.serialize(foryValue);
914 return () => {
915 const decoded = dataset.foryReader.deserialize(bytes);
916 blackhole ^= Array.isArray(decoded) ? decoded.length : 1;
917 };
918 }
919
920 if (serializerName === "protobuf") {
921 const protoValue = dataset.toProto(value);
922 if (operation === "Serialize") {
923 return () => {
924 const bytes = dataset.protoType.encode(protoValue).finish();
925 blackhole ^= bytes.length;
926 };
927 }
928 const bytes = dataset.protoType.encode(protoValue).finish();
929 return () => {
930 const decoded = dataset.protoType.decode(bytes);
931 blackhole ^= decoded ? 1 : 0;
932 };
933 }
934
935 if (serializerName === "json") {
936 if (operation === "Serialize") {
937 return () => {
938 const json = JSON.stringify(value);
939 blackhole ^= json.length;
940 };
941 }
942 const json = JSON.stringify(value);
943 return () => {
944 const decoded = JSON.parse(json);
945 blackhole ^= Array.isArray(decoded) ? decoded.length : 1;
946 };
947 }
948
949 throw new Error(`Unknown serializer ${serializerName}`);
950}
951
952function measureBatch(fn, batchSize) {
953 const start = process.hrtime.bigint();

Callers 1

buildResultsFunction · 0.85

Calls 9

normalizeForyValueFunction · 0.85
toProtoMethod · 0.80
serializeMethod · 0.65
deserializeMethod · 0.65
encodeMethod · 0.65
decodeMethod · 0.65
isArrayMethod · 0.45
finishMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected