This file contains hidden or 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 timers.js | |
| setInterval(ƒ,1) -> (µs) : | |
| [ 1477, | |
| 1172, | |
| 1071, | |
| 1084, | |
| 1122, | |
| 1145, | |
| 1064, | |
| 1062, |
This file contains hidden or 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-09-13 jorge@jorgechamorro.com | |
| var ctr, i, t, k= 1e8; | |
| function ƒ (i) { ctr+= i } | |
| function begin () { i= k, ctr= 0; while (Date.now() === (t= Date.now())) ; } | |
| function end (s,t) { console.log(s+ ((Date.now()- t)*1e6/k).toFixed(2)+ 'ns') } | |
| begin(); |
This file contains hidden or 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-06-28 js_vs_c.c | |
| #include <stdio.h> | |
| #include <unistd.h> | |
| #include <sys/time.h> | |
| long long DateNow () { | |
| struct timeval time; | |
| gettimeofday(&time, NULL); | |
| return (long long) ((time.tv_sec* 1000000) + time.tv_usec); |
This file contains hidden or 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-06-28 js_vs_c.js | |
| var c= 0; | |
| var t= Date.now()+1e3; | |
| while (c++, (now= Date.now()) < t) ; | |
| console.log(c); |
This file contains hidden or 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-06-28 functionCall.c jorge@jorgechamorro.com | |
| /* | |
| $ gcc -O0 /Users/jorge/Desktop/functionCall.c | |
| $ ./a.out | |
| without a function call: 2.789478 ns per iteration | |
| with a function call : 3.574004 ns per iteration | |
| With the function call it's 28.124473 percent slower than without the function call | |
| */ |
This file contains hidden or 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
| unibody:node-threads-a-gogo jorge$ which node | |
| /Users/jorge/JAVASCRIPT/binarios/bin/node | |
| unibody:node-threads-a-gogo jorge$ node -v | |
| v0.6.17 | |
| unibody:node-threads-a-gogo jorge$ node -e 'console.log(process.versions)' | |
| { node: '0.6.17', | |
| v8: '3.6.6.25', | |
| ares: '1.7.5-DEV', | |
| uv: '0.6', | |
| openssl: '0.9.8l' } |
This file contains hidden or 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-05-19 jorge@jorgechamorro.com | |
| var o; | |
| function boot () { | |
| o= {}; | |
| var i= 7e6; | |
| while (i--) { | |
| var key= i.toString(36); | |
| o[key]= { id:key }; | |
| } |
This file contains hidden or 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 hidden or 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 PDFDocument= require('pdfkit'); | |
| var doc= new PDFDocument(); | |
| doc.save(); | |
| doc.x= doc.pages[0].width/2; | |
| doc.y= doc.pages[0].height/2; | |
| doc.fontSize(30); | |
| doc.rotate(89.9, {origin: [doc.x, doc.y]}); | |
| doc.text('OK, GOOD'); |
This file contains hidden or 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); | |
| } | |
| } |