       time = time / div
     print
 
-###########################################################################################
-
-run = (size, callback) ->
-  # Prepare the pipe
-  input = new Generator
-  buffer = new BufferedStream size
-  output = fs.createWriteStream "#{__dirname}/speed.#{pretty.bytes size}.out"
-  # Call the pipe
-  input.pipe(buffer).pipe(output)
-  # See how that worked
-  output.on 'error', (err)->
-    console.log err
-  output.on 'close', ->
-    callback()
-
-check = (size, callback) ->
-  exec "md5 #{__dirname}/speed.#{pretty.bytes(size).replace(' ','\\ ')}.out", (err, stdout, stderr) ->
-    /\ (\w*)$/.exec(stdout.trim())[1].should.eql md5
-    callback()
-
-each(sizes)
-.on 'item', (next, size) ->
-  time = Date.now()
-  each()
-  .times(times)
-  .on 'item', (next) ->
-    run size, ->
-      check size, next
-  .on 'error', ->
-    next()
-  .on 'end', ->
-    console.log pad(pretty.bytes(size), 7), ':', pretty.time((Date.now()-time)/times)
-    next()
-.on 'error', (e) ->
-  console.log e
-.on 'end', ->
+each([
+  require '../src/FixedBufferedStream'
+  require '../src/StackBufferedStream'
+])
+.on 'item', (next, BufferedStream) ->
+  each([
+    {lines: 100000, md5: '9229fad768f525f6cac64bd158f6e022'}
+    {lines: 1000000, md5: 'e837b60bbab8cb38259ff7b135a98aba'}
+  ])
+  .on 'item', (next, item) ->
+    {lines, md5} = item
+    each(sizes)
+    .on 'item', (next, size) ->
+      time = Date.now()
+      each()
+      .times(times)
+      .on 'item', (next) ->
+        # Prepare the pipe
+        input = new Generator lines
+        buffer = new BufferedStream size
+        output = fs.createWriteStream "#{__dirname}/speed.#{pretty.bytes size}.out"
+        # Call the pipe
+        input.pipe(buffer).pipe(output)
+        # See how that worked
+        output.on 'error', (err)->
+          console.log err
+        output.on 'close', ->
+          # Validate file md5
+          exec "md5 #{__dirname}/speed.#{pretty.bytes(size).replace(' ','\\ ')}.out", (err, stdout, stderr) ->
+            /\ (\w*)$/.exec(stdout.trim())[1].should.eql md5
+            next()
+      .on 'error', ->
+        next()
+      .on 'end', ->
+        console.log pad(pretty.bytes(size), 7), ':', pretty.time((Date.now()-time)/times)
+        next()
+    .on 'both', next
+  .on 'both', next
+.on 'error', (err) ->
+  console.error err
+.on 'end', (err) ->
   console.log 'done'

each = require 'each'
pad = require 'pad'

###########################################################################################

# lines = 100000
# md5 = '9229fad768f525f6cac64bd158f6e022'
lines = 1000000
md5 = 'e837b60bbab8cb38259ff7b135a98aba'
sizes = [
  0
  64

  1024*1024*64
  1024*1024*128
]
times = 3

Generator = (@lines) ->
  @count = 0
  @readable = true
  process.nextTick @resume.bind @
