Skip to content

Instantly share code, notes, and snippets.

View brendanashworth's full-sized avatar
🐦
bunting

Brendan Ashworth brendanashworth

🐦
bunting
View GitHub Profile
@brendanashworth
brendanashworth / gist:22276e94826e9a49c357
Created April 8, 2015 06:17
process.binding() vs module load require() benchmark
var time = 1e3;
function benchBinding() {
console.time('bench-binding');
for (var i = 0; i < time; i++) {
var Process = process.binding('process_wrap').Process;
var WriteWrap = process.binding('stream_wrap').WriteWrap;
var uv = process.binding('uv');
@brendanashworth
brendanashworth / gist:05c64dd065e3060771b8
Created March 24, 2015 00:52
artisan-validator concatenate errors into single string
var validator = require('artisan-validator')();
validator.try(... function(errors) {
var msg = Object.keys(result.errors).map(function(name) {
return result.errors[name].join(' ');
})[0];
});
@brendanashworth
brendanashworth / handlefiles.js
Created January 25, 2015 00:09
Express: use handlefiles to .render()
// Middleware for attaching the Handlefiles engine to ExpressJS
// Kind of hacky, since we attach it directly to express/lib/response
var path = require('path');
var handlefiles = require('handlefiles');
var Response = require('express/lib/response');
var viewDirectory = path.join(__dirname, '..', 'views');
/**
* Configures Express to use the correct view engine.
$ vagrant init hashicorp/precise32
$ vagrant up

Results

Adding loop

coffee CLI

real	0m0.124s
user	0m0.102s
sys	0m0.022s
total = 0
for num in [1..5000]
total += num
console.log total
{
"name": "bench",
"version": "0.0.2",
"repo": "brendanashworth/bench",
"description": "Easy to use, beautiful-looking benchmarking library",
"keywords": ["benchmark", "bench", "speed"],
"license": "MIT",
"src": ["bench.h", "bench.c"]
}
function Person(age) {
if (age > 18) this.age = age;
}
Person.prototype.age = 18;
Client.prototype.zipcode = 12345;
// Utilizes a closure
Client.prototype.defaultAge = (function() {
return prompt("What should the default age be?");
})();