* Benchmarks status code handling
()
| 322 | * Benchmarks status code handling |
| 323 | */ |
| 324 | function benchmarkStatusCodeHandling () { |
| 325 | console.log("📊 Status Code Handling Performance"); |
| 326 | console.log("-".repeat(40)); |
| 327 | |
| 328 | const customSerializer = serializers.get("application/json"); |
| 329 | const suite = new Benchmark.Suite(); |
| 330 | |
| 331 | const statusCodes = [200, 201, 400, 404, 500]; |
| 332 | |
| 333 | for (const status of statusCodes) { |
| 334 | suite.add(`Custom - Status ${status}`, () => { |
| 335 | if (status >= 400) { |
| 336 | customSerializer(null, new Error(`Error ${status}`), status, false); |
| 337 | } else { |
| 338 | customSerializer(testData.simple, null, status); |
| 339 | } |
| 340 | }); |
| 341 | } |
| 342 | |
| 343 | suite |
| 344 | .on("cycle", event => { |
| 345 | console.log(` ${String(event.target)}`); |
| 346 | }) |
| 347 | .on("complete", function () { |
| 348 | console.log(` Fastest: ${this.filter("fastest").map("name")}\n`); |
| 349 | }) |
| 350 | .run({ async: false }); |
| 351 | } |
| 352 | |
| 353 | /** |
| 354 | * Main execution function |