var http = require('http')
var util = require('util')
var sigmund = require('./sigmund.js')
var sreq, sres, creq, cres, test
http.createServer(function (q, s) {
this.close(function () { setTimeout(function () {
}).listen(1337, function () {
creq = http.get({ port: 1337 })
creq.on('response', function (s) { cres = s })
test = [sreq, sres, creq, cres]
for (var i in exports.compare) {
var hash = exports.compare[i]()
require('bench').runMain()
function customWs (obj, md, d) {
if (to === 'undefined' || to === 'function' || to === null) return ''
if (d > md || !obj || to !== 'object') return ('' + obj).replace(/[\n ]+/g, '')
if (Array.isArray(obj)) {
return obj.map(function (i, _, __) {
return customWs(i, md, d + 1)
}).reduce(function (a, b) { return a + b }, '')
var keys = Object.keys(obj)
return keys.map(function (k, _, __) {
return k + ':' + customWs(obj[k], md, d + 1)
}).reduce(function (a, b) { return a + b }, '')
function custom (obj, md, d) {
if (to === 'undefined' || to === 'function' || to === null) return ''
if (d > md || !obj || to !== 'object') return '' + obj
if (Array.isArray(obj)) {
return obj.map(function (i, _, __) {
return custom(i, md, d + 1)
}).reduce(function (a, b) { return a + b }, '')
var keys = Object.keys(obj)
return keys.map(function (k, _, __) {
return k + ':' + custom(obj[k], md, d + 1)
}).reduce(function (a, b) { return a + b }, '')
function sparseFE2 (obj, maxDepth) {
if (depth > maxDepth) return
if (typeof v === 'function' || typeof v === 'undefined') return
if (typeof v !== 'object' || !v) {
if (seen.indexOf(v) !== -1 || depth === maxDepth) return
Object.keys(v).forEach(function (k, _, __) {
if (k.charAt(0) === '_') return
if (to === 'function' || to === 'undefined') return
function sparseFE (obj, maxDepth) {
if (depth > maxDepth) return
if (typeof v === 'function' || typeof v === 'undefined') return
if (typeof v !== 'object' || !v) {
if (seen.indexOf(v) !== -1 || depth === maxDepth) return
Object.keys(v).forEach(function (k, _, __) {
if (k.charAt(0) === '_') return
if (to === 'function' || to === 'undefined') return
function sparse (obj, maxDepth) {
if (depth > maxDepth) return
if (typeof v === 'function' || typeof v === 'undefined') return
if (typeof v !== 'object' || !v) {
if (seen.indexOf(v) !== -1 || depth === maxDepth) return
if (k.charAt(0) === '_') continue
if (to === 'function' || to === 'undefined') continue
function noCommas (obj, maxDepth) {
if (depth > maxDepth) return
if (typeof v === 'function' || typeof v === 'undefined') return
if (typeof v !== 'object' || !v) {
if (seen.indexOf(v) !== -1 || depth === maxDepth) return
if (k.charAt(0) === '_') continue
if (to === 'function' || to === 'undefined') continue
function flatten (obj, maxDepth) {
if (depth > maxDepth) return
if (typeof v === 'function' || typeof v === 'undefined') return
if (typeof v !== 'object' || !v) {
if (seen.indexOf(v) !== -1 || depth === maxDepth) return
if (k.charAt(0) === '_') continue
if (to === 'function' || to === 'undefined') continue
'JSON.stringify (guarded)': function () {
return JSON.stringify(test, function (k, v) {
if (typeof v !== 'object' || !v) return v
if (seen.indexOf(v) !== -1) return undefined
'flatten 10': function () {
'noCommas 10': function () {
return noCommas(test, 10)
'sparse 10': function () {
'sparseFE 10': function () {
return sparseFE(test, 10)
'sparseFE2 10': function () {
return sparseFE2(test, 10)