Skip to content

Instantly share code, notes, and snippets.

View mafintosh's full-sized avatar

Mathias Buus mafintosh

View GitHub Profile
{
valueSize: 37,
length: 100242424,
values: [ /* all of the above is white space padded to 64 bytes */
{key: ..., },/* padding */
{key: ...
]
}
function iterate (db, onnode, done) {
visit(db, [], onnode, cb)
}
function visit (db, path, onnode, cb) {
var val = 0
loop(null)
function loop (err) {
if (err) return cb(err)
git-checkout-fork () {
local REPO=$(basename $PWD)
local USERNAME=$(echo $1 | sed 's|:.*||')
local FORK=$(echo $1 | sed 's|.*:||')
if [ "$(git remote | grep ^$USERNAME\$ 2>/dev/null)" == "" ]; then
git remote add $USERNAME git://github.com/$USERNAME/$REPO
fi
git checkout -B $USERNAME-$FORK
@mafintosh
mafintosh / binding.gyp
Last active March 9, 2018 13:19
napi-crash
{
"targets": [{
"target_name": "async_worker_test",
"sources": [
"./test.c"
],
"xcode_settings": {
"OTHER_CFLAGS": [
"-O3",
"-std=c99",
@mafintosh
mafintosh / autocannon-against-http.txt
Created March 1, 2018 15:27
autocannon + turbo-net experiments
Running 10s test @ http://127.0.0.1:8080
10 connections
Stat Avg Stdev Max
Latency (ms) 0.05 0.23 7.63
Req/Sec 15811.28 1290.87 17155
Bytes/Sec 1.76 MB 143 kB 1.9 MB
174k requests in 11s, 19.3 MB read
var http = require('http')
var fs = require('fs')
var server = http.createServer(function (req, res) {
fs.createReadStream('/home/maf/downloads/big.file')
.pipe(res)
})
server.listen(10000)
/* ASYNC TIME | ASYNC OPS | DIRECT ASYNC OPS | */
/* | | | */ var http = require('http')
/* | | | */ var fs = require('fs')
/* | | | */
/* | | | */ var filename = __filename
/* | | | */
/* | | | */ var server = http.createServer(function (req, res) {
/* 1804 | 2239 | 2239 | */ fs.stat(filename, function (err) {
/* | | | */ if (err) return res.end()
/* 124957 | 31351 | 2239 | */ fs.createReadStream(filename)
/* TIME | ASYNC OPS | */
/* | | */ var http = require('http')
/* | | */ var fs = require('fs')
/* | | */
/* | | */ var filename = __filename
/* | | */
/* | | */ var server = http.createServer(function (req, res) {
/* 1873 | 2238 | */ fs.stat(filename, function (err) {
/* | | */ if (err) return res.end()
/* 126368 | 33581 | */ fs.createReadStream(filename).pipe(res)
confidence improvement accuracy (*) (**) (***)
process/next-tick-breadth-args.js millions=4 *** 29.97 % ±2.02% ±2.70% ±3.53%
process/next-tick-breadth.js millions=4 ** 3.99 % ±2.41% ±3.21% ±4.19%
process/next-tick-depth-args.js millions=12 *** 4.07 % ±0.64% ±0.85% ±1.11%
process/next-tick-depth.js millions=12 *** 16.11 % ±1.35% ±1.80% ±2.34%
process/next-tick-exec-args.js millions=5 *** 23.27 % ±1.29% ±1.72% ±2.25%
process/next-tick-exec.js millions=5 *** 68.86 % ±3.77% ±5.03% ±6.58%
Be aware that when doing many comparisions the risk of a false-positive
result increases. In this case there are 6 comparisions, you can thus
const stream = require('stream')
const cache = new Map() // you might wanna use an lru here
function createCacheStream (url) {
const buf = []
return stream.Transform({
transform: function (data, enc, cb) {
buffer.push(data)
cb(null, data)
},