Skip to content

Instantly share code, notes, and snippets.

View brendanashworth's full-sized avatar
🐦
bunting

Brendan Ashworth brendanashworth

🐦
bunting
View GitHub Profile
{
"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"]
}
total = 0
for num in [1..5000]
total += num
console.log total

Results

Adding loop

coffee CLI

real	0m0.124s
user	0m0.102s
sys	0m0.022s
$ vagrant init hashicorp/precise32
$ vagrant up
@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.
@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 / 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');
// Licensed io.js code
posix.relative = function(from, to) {
assertPath(from);
assertPath(to);
from = posix.resolve(from).substr(1);
to = posix.resolve(to).substr(1);
function trim(arr) {
var start = 0;
@brendanashworth
brendanashworth / binding.cc
Created June 5, 2015 00:34
node::AtExit callback test
#include <node.h>
#include <stdio.h>
using namespace v8;
void Exit(void* arg) {
printf("node::AtExit called\n");
}
void Initialize(Handle<Object> exports) {