$ node bench-01-pull-stream.js
pull3*100000: 1995.798ms
pull_compose*100000: 1968.901ms
pull_chain*100000: 1871.930ms
$ node bench-02-async-stream.js
async3*100000: 3295.666ms
async3*100000: 3145.636ms
async3*100000: 2943.988ms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const hyperdrive = require('hyperdrive') | |
const src = `/tmp/${Math.random()}/` | |
console.log(src) | |
const storage = require('dat-storage')(src) | |
const archive = hyperdrive(storage, { latest: true, indexing: true }) | |
archive.writeFile('/dat.json', 'hi', err => { | |
if (err) throw err |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const src = `/tmp/${Math.random()}` | |
Dat(src, (err, dat) => { | |
if (err) throw err | |
dat.archive.writeFile('/dat.json', 'hi', err => { | |
if (err) throw err | |
console.log(fs.readFileSync(`${src}/dat.json`)) // => empty | |
dat.archive.readFile('/dat.json', (err, data) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/juliangruber/async-stream | |
function heap (name, Stream) { | |
var start = Date.now() | |
var heap = process.memoryUsage().heapUsed | |
var a = [], N = 100000 | |
for(var i = 0; i < N; i++) | |
a.push(Stream()) | |
console.log(name, (process.memoryUsage().heapUsed - heap)/N, (Date.now()-start)) | |
a = null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const writeToRemote = new PassThrough() | |
reconnect(async con => { | |
await sendState(con) | |
writeToRemote.pipe(con) | |
}).on('disconnect', () => { | |
writeToRemote.unpipe() | |
}) | |
theRestOfYourProgram.pipe(writeToRemote) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var domain = require('domain'); | |
var EventEmitter = require('events').EventEmitter; | |
var inner = function (ee1, ee2, cb1, cb2) { | |
var domain1 = domain.createDomain(); | |
domain1.on('error', function (err) { | |
domain1.dispose(); | |
cb2(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Rating = require('rating'); | |
var insertCSS = require('insert-css'); | |
insertCSS('.star { color: gray } .star.glow { color: brown }'); | |
var rating = new Rating([1, 2, 3, 4, 5]); | |
document.body.appendChild(rating.el); | |
var current = document.createElement('p'); | |
document.body.appendChild(current); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var rad = require('random-access-directory') | |
var store = rad(procss.env.HOME + '/.dat/') | |
// create a first store | |
store = store('hypercore.txt') | |
store.get(0, ...) | |
// create another store, based on the first one | |
// this way modules can pass the store instance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
index(feed, { | |
start: 0, | |
end: Infinity, | |
key: feed.key | |
}, function onentry (entry, cb) { | |
cb() | |
}, function ondone () { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http') | |
http.createServer((req, res) => { | |
res.write('<!DOCTYPE html><html><head><title>electron-stream</title><script>') | |
res.write('console.log("hi");\n') | |
setTimeout(() => { | |
res.write('console.log("you");\n') | |
res.end('</script></head></html>') | |
}, 3000) | |
}).listen(8000, () => console.log('8000')) |