Skip to content

Instantly share code, notes, and snippets.

View billywhizz's full-sized avatar
🤓
always be learning

Andrew Johnston billywhizz

🤓
always be learning
View GitHub Profile
@billywhizz
billywhizz / bench.js
Created June 24, 2011 04:54
comparing buffalo BSON v JSON
var buffalo = require("../buffalo");
function test(obj, iter, fn, name) {
var then = new Date().getTime();
var p;
var runs = 0;
while(iter--) {
p = fn(obj);
runs++
}
@billywhizz
billywhizz / lineparse.js
Created July 7, 2011 15:37
line parsing with node.js
var lineParser = function(_command) {
var _parser = this;
if(!_command) _command = new Buffer(1024);
var _loc = 0;
_parser.execute = function(buffer, start, len) {
var end = start + len;
if(start > end) {
if(_parser.onError) _parser.onError(new Error("out of range"));
return -1;
function handleFailure(err) {
next(new DbError(err));
}
function findBlog(blog) {
function setUsers() {
// do stuff
}
function setBlog() {
function handleFailure(err) {
next(new DbError(err));
}
function findBlogCb(blog) {
var proj;
function setBlogCb() {
proj.setUsers(users).on("success", setUsersCb).on("failure", handleFailure);
}
function Adder(cb) {
var _adder = this;
var _complete = false;
var _result = 0;
var _jobs = 0;
_adder.add = function(x,y) {
setTimeout(function() {
_result += (x+y);
_jobs--;
@billywhizz
billywhizz / testloop.c
Created July 16, 2011 17:39
testing cpu write combining performance characteristics with loops
#include <stdio.h>
#include <stdint.h>
#define ITEMS 1<<24
#define ITER 10 * 1024 * 1024;
static int A1[ITEMS];
static int A2[ITEMS];
static int A3[ITEMS];
static int A4[ITEMS];
@billywhizz
billywhizz / testloop.c
Created July 16, 2011 17:39
testing cpu write combining performance characteristics with loops
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
/*
This program tests the performance characteristics of write combining
On an intel CPU only 4 writes at a time will be combined so we should see
a big performance improvement if we only write to distinct memory locations
<=4 times per iteration of a loop
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/time.h>
#define P 2
static uint64_t volatile counter = 0;
pthread_mutex_t mutex;
@billywhizz
billywhizz / fib.js
Created December 1, 2011 14:51
cluster example
var cluster = require('cluster');
function fib (n) {
if (n < 2) {
return 1;
}
else {
return fib(n-2) + fib(n-1);
}
}
@billywhizz
billywhizz / bufftest.js
Created December 3, 2011 18:25
testing buffer write performance
Buffer.prototype.xwriteUInt8 = function(value, offset) {
this[offset] = value & 0xff;
}
Buffer.prototype.xwriteUInt16BE = function(value, offset) {
this[offset++] = (value >>> 8) & 0xff;
this[offset] = value & 0xff;
}
Buffer.prototype.xwriteUInt32BE = function(value, offset) {