(serializerName, dataset, operation)
| 900 | } |
| 901 | |
| 902 | function 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 | |
| 952 | function measureBatch(fn, batchSize) { |
| 953 | const start = process.hrtime.bigint(); |
no test coverage detected