Skip to content

Instantly share code, notes, and snippets.

@fengmk2
Created September 12, 2016 10:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fengmk2/d7d0091a5eeae8ce0c9580f31e748371 to your computer and use it in GitHub Desktop.
Save fengmk2/d7d0091a5eeae8ce0c9580f31e748371 to your computer and use it in GitHub Desktop.
get header using lower case
'use strict';
const Benchmark = require('benchmark');
const benchmarks = require('beautify-benchmark');
const suite = new Benchmark.Suite();
suite
.add('get header all lower case', function() {
const res = {};
res['x-frame-options1'] = 'X-Frame-Options1 value';
res['x-frame-options2'] = 'X-Frame-Options2 value';
res['x-frame-options3'] = 'X-Frame-Options3 value';
res['x-frame-options1'.toLowerCase()];
res['x-frame-options2'.toLowerCase()];
res['x-frame-options3'.toLowerCase()];
})
.add('get header mixed case', function() {
const res = {};
res['x-frame-options1'] = 'X-Frame-Options1 value';
res['x-frame-options2'] = 'X-Frame-Options2 value';
res['x-frame-options3'] = 'X-Frame-Options3 value';
res['X-Frame-Options1'.toLowerCase()];
res['X-Frame-Options2'.toLowerCase()];
res['X-Frame-Options3'.toLowerCase()];
})
.on('cycle', event => {
benchmarks.add(event.target);
})
.on('start', () => {
console.log('\n res.getHeader() Benchmark\n node version: %s, date: %s\n Starting...',
process.version, Date());
})
.on('complete', () => {
benchmarks.log();
})
.run({ async: false });
// res.getHeader() Benchmark
// node version: v6.5.0, date: Mon Sep 12 2016 18:22:37 GMT+0800 (CST)
// Starting...
// 2 tests completed.
//
// get header all lower case x 7,139,523 ops/sec ±1.13% (85 runs sampled)
// get header mixed case x 1,222,787 ops/sec ±5.13% (76 runs sampled)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment