Skip to content

Instantly share code, notes, and snippets.

@atian25
Created September 20, 2016 09:50
Show Gist options
  • Save atian25/a88d0fb7c1011b61c4b07b9e635a6c21 to your computer and use it in GitHub Desktop.
Save atian25/a88d0fb7c1011b61c4b07b9e635a6c21 to your computer and use it in GitHub Desktop.
get header use lowercase, 10x speed
'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