Skip to content

Instantly share code, notes, and snippets.

@fengmk2
Created August 30, 2016 13:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fengmk2/1634043ec1d40e09b53197b817411131 to your computer and use it in GitHub Desktop.
Save fengmk2/1634043ec1d40e09b53197b817411131 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 });
@fengmk2
Copy link
Author

fengmk2 commented Aug 30, 2016

node set-header.js 


  res.setHeader() Benchmark
  node version: v4.5.0, date: Tue Aug 30 2016 21:26:39 GMT+0800 (CST)
  Starting...
  2 tests completed.

  setHeader() normal     x 241,970 ops/sec ±3.40% (82 runs sampled)
  setHeader() lower case x 626,429 ops/sec ±1.50% (85 runs sampled)

@JacksonTian
Copy link

JacksonTian commented Aug 31, 2016

  var key = name.toLowerCase();
  this._headers[key] = value;
  this._headerNames[key] = name;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment