* Benchmarks error handling performance
()
| 206 | * Benchmarks error handling performance |
| 207 | */ |
| 208 | function benchmarkErrorHandling () { |
| 209 | console.log("📊 Error Handling Performance"); |
| 210 | console.log("-".repeat(40)); |
| 211 | |
| 212 | const customSerializer = serializers.get("application/json"); |
| 213 | const plainSerializer = serializers.get("text/plain"); |
| 214 | const suite = new Benchmark.Suite(); |
| 215 | |
| 216 | suite |
| 217 | .add("Custom - Error object with stack", () => { |
| 218 | customSerializer(null, testErrors.complex, 500, true); |
| 219 | }) |
| 220 | .add("Custom - Error object without stack", () => { |
| 221 | customSerializer(null, testErrors.complex, 500, false); |
| 222 | }) |
| 223 | .add("Plain - Error object with stack", () => { |
| 224 | plainSerializer(null, testErrors.complex, 500, true); |
| 225 | }) |
| 226 | .add("Plain - Error object without stack", () => { |
| 227 | plainSerializer(null, testErrors.complex, 500, false); |
| 228 | }) |
| 229 | .add("Custom - String error", () => { |
| 230 | customSerializer(null, "Error message", 400, false); |
| 231 | }) |
| 232 | .add("Plain - String error", () => { |
| 233 | plainSerializer(null, "Error message", 400, false); |
| 234 | }) |
| 235 | .on("cycle", event => { |
| 236 | console.log(` ${String(event.target)}`); |
| 237 | }) |
| 238 | .on("complete", function () { |
| 239 | console.log(` Fastest: ${this.filter("fastest").map("name")}\n`); |
| 240 | }) |
| 241 | .run({ async: false }); |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * Benchmarks data size impact on serialization performance |