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
/* | |
$ node bench.js | |
Threads_a_gogo JS thread -> 4624 (ms) 298607040 | |
Node's main JS thread -> 8471 (ms) 298607040 | |
Ratio: 1.83 times faster | |
*/ | |
function fib (n) { |
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 http = require('http') | |
var pool = require('threads_a_gogo').createPool(5).all.eval(fib); | |
function fib (n) { | |
if (n < 2) { | |
return 1; | |
} else { | |
return fib(n - 2) + fib(n - 1); | |
} | |
} |
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
jorge@UbuntuParallels:~$ git clone http://github.com/xk/node-threads-a-gogo.git | |
Cloning into node-threads-a-gogo... | |
remote: Counting objects: 112, done. | |
remote: Compressing objects: 100% (90/90), done. | |
remote: Total 112 (delta 16), reused 112 (delta 16) | |
Receiving objects: 100% (112/112), 59.80 KiB | 84 KiB/s, done. | |
Resolving deltas: 100% (16/16), done. | |
jorge@UbuntuParallels:~$ cd node-threads-a-gogo/ | |
jorge@UbuntuParallels:~/node-threads-a-gogo$ node-waf configure install |
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
/* | |
2012-04-22 jorge@jorgechamorro.com | |
MacBookPro5,4 core2duo @ 2.53GHz, node v0.7.5: | |
loopsPerSecond: 103412616.3, nextTicksPerSecond: 671885.8, ratio: 153.9x times faster | |
beagleboard beaglebone @ 500Mhz: | |
loopsPerSecond: 6781040.2, nextTicksPerSecond: 27472.4, ratio: 246.8x times faster | |
*/ |
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
// 20111028 jorge@jorgechamorro.com | |
// How to subclass Array | |
// In reply to https://gist.github.com/1100841/9c959db9314338a09c0f288c2c0ca5553816e400 | |
function subArray () { | |
var nu= Array.apply(null, arguments); | |
nu.__proto__= subArray.prototype; | |
return nu; | |
} |
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
// 2011-09-15 jorge@jorgechamorro.com | |
// http://groups.google.com/group/nodejs-dev/msg/cf392e131b5fcd3a | |
// http://groups.google.com/group/nodejs-dev/browse_thread/thread/922a30cf88a1b784 | |
var ms= 5; | |
var ctr= 0; | |
var RUN= 1; | |
function f () { | |
if (RUN) { |
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 appStatus; | |
process.on('uncaughtException', function globalErrHandler (error) { | |
console.log('An error happened when the appStatus was '+ appStatus); | |
switch (appStatus) { | |
case 1: //recover from status 1 | |
case 2: //idem from status 2 | |
case 3: //etc. |
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 crypto = require('crypto'); | |
var key = "some keys are better than others"; | |
var msg = "Attack Troy from within a wooden horse!"; | |
var CYPHER = "aes256"; | |
var test = function(msg) { | |
var cypher = crypto.createCipher(CYPHER, key); | |
var enc_msg = cypher.update(msg, "utf8", 'binary'); | |
enc_msg += cypher.final('binary'); |
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
/* | |
problem2.js, 20110501 jorge@jorgechamorro.com | |
to run: $node --expose-gc problem2.js | |
problem2.js is just like problem.js, but does a gc() whenever a BAD happens. | |
After the gc() it runs fine again for quite while, so the problem must have something to do with the GC. | |
****************** |
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
// sets kCount timeouts of no more than 5 ms using floats and using integers | |
// and logs the times at which they are actually triggered. | |
var t0; | |
var log= []; | |
var kCount= 20; | |
function go () { | |
var i= kCount; | |
var cb= f('FLOAT'); |