Created
July 16, 2014 15:15
-
-
Save shinout/d7c553d4a27d21963239 to your computer and use it in GitHub Desktop.
comparing performance of fs.readSync() with that of fs.read()
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
N = 100000 | |
READ_SIZE = 100 | |
fs = require "fs" | |
fd = fs.openSync __filename, "r" | |
i = 0 | |
console.time "sync" | |
while i < N | |
fs.readSync fd, new Buffer(100), 0 , READ_SIZE, 0 | |
i++ | |
console.timeEnd "sync" | |
i = 0 | |
console.time "async_chain" | |
fn = -> | |
fs.read fd, new Buffer(100), 0 , READ_SIZE, 0, -> | |
i++ | |
if i < N | |
fn() | |
else | |
console.timeEnd "async_chain" | |
async_aside() | |
fn() | |
async_aside = -> | |
console.time "async_aside" | |
i = 0 | |
results = 0 | |
while i < N | |
fs.read fd, new Buffer(100), 0 , READ_SIZE, 0, -> | |
results++ | |
if results is N | |
console.timeEnd "async_aside" | |
i++ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sync: 210ms
async_chain: 1870ms
async_aside: 1671ms
Unfortunate results.....