Skip to content

Instantly share code, notes, and snippets.

@shinout
Created July 16, 2014 15:15
Show Gist options
  • Save shinout/d7c553d4a27d21963239 to your computer and use it in GitHub Desktop.
Save shinout/d7c553d4a27d21963239 to your computer and use it in GitHub Desktop.
comparing performance of fs.readSync() with that of fs.read()
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++
@shinout
Copy link
Author

shinout commented Jul 16, 2014

sync: 210ms
async_chain: 1870ms
async_aside: 1671ms

Unfortunate results.....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment