Skip to content

Instantly share code, notes, and snippets.

@atian25
Forked from fengmk2/set-header.js
Created August 31, 2016 03:20
Show Gist options
  • Save atian25/8d9998b585ac31d18cdc963f6be82642 to your computer and use it in GitHub Desktop.
Save atian25/8d9998b585ac31d18cdc963f6be82642 to your computer and use it in GitHub Desktop.
set header benchmark
'use strict';
const OutgoingMessage = require('http').OutgoingMessage;
'use strict';
const Benchmark = require('benchmark');
const benchmarks = require('beautify-benchmark');
const suite = new Benchmark.Suite();
suite
.add('setHeader() normal', () => {
const res = new OutgoingMessage();
res.setHeader('X-Frame-Options1', 'X-Frame-Options1 value');
res.setHeader('X-Frame-Options2', 'X-Frame-Options2 value');
res.setHeader('X-Frame-Options3', 'X-Frame-Options3 value');
})
.add('setHeader() lower case', () => {
const res = new OutgoingMessage();
res.setHeader('x-frame-options1', 'X-Frame-Options1 value');
res.setHeader('x-frame-options2', 'X-Frame-Options2 value');
res.setHeader('x-frame-options3', 'X-Frame-Options3 value');
})
.on('cycle', event => {
benchmarks.add(event.target);
})
.on('start', event => {
console.log('\n res.setHeader() Benchmark\n node version: %s, date: %s\n Starting...',
process.version, Date());
})
.on('complete', () => {
benchmarks.log();
})
.run({ 'async': false });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment