Skip to content

Instantly share code, notes, and snippets.

@steelThread
Created July 24, 2011 17:47
Show Gist options
  • Save steelThread/1102873 to your computer and use it in GitHub Desktop.
Save steelThread/1102873 to your computer and use it in GitHub Desktop.
Client codez
#
# Reads xml in chunks, parses to js obj.
#
net = require 'net'
sys = require 'sys'
xml2js = require 'xml2js'
start = new Date().getMilliseconds()
parser = new xml2js.Parser()
buffer = ''
count = 0
endTag = '</MLB-event>'
socket = new net.Socket()
socket.setEncoding 'utf8'
socket.connect 8124, 'ec2-50-19-181-80.compute-1.amazonaws.com'
socket.on 'data', (chunk) ->
buffer += chunk
parseEvents()
parser.on 'end', -> count++
parseEvents = ->
end = buffer.indexOf endTag
if end isnt -1
end += endTag.length
parser.parseString buffer.slice(0, end)
buffer = buffer.substr end
parseEvents()
process.on 'exit', ->
console.log "took #{new Date().getMilliseconds() - start}ms"
console.log "received #{count} events"
@steelThread
Copy link
Author

Getting between 250 - 270ms to consume and parse all 1000 events.

$ coffee client.coffee
took 250ms
received 1000 events

$ coffee client.coffee
took 248ms
received 1000 events

$ coffee client.coffee
took 252ms
received 1000 events

$ coffee client.coffee
took 277ms
received 1000 events

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