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
#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 / 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
@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];
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--;
function handleFailure(err) {
next(new DbError(err));
}
function findBlogCb(blog) {
var proj;
function setBlogCb() {
proj.setUsers(users).on("success", setUsersCb).on("failure", handleFailure);
}
function handleFailure(err) {
next(new DbError(err));
}
function findBlog(blog) {
function setUsers() {
// do stuff
}
function setBlog() {
@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;
@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 / f2s.js
Created May 24, 2011 00:17
sendfile to a socket
var fs = require("fs");
var constants = process.binding("constants");
exports.f2s = function(file, socket, off, len, cb, chunked) {
var twrite = 0;
var chunksize = len < 4096?len:4096;
function chunk() {
try {
if(chunked) {
if(off + chunksize > len) chunksize = len - off;
@billywhizz
billywhizz / mylib.js
Created May 19, 2011 14:41
module configuration example
// this is just a standard node.js module
exports.foo = function() {
return ("hello from " + process.ARGV[2]);
}