Skip to content

Instantly share code, notes, and snippets.

@runvnc
Last active December 15, 2015 14:19
Show Gist options
  • Save runvnc/5273247 to your computer and use it in GitHub Desktop.
Save runvnc/5273247 to your computer and use it in GitHub Desktop.
Guillaume Lecomte's Node.js performance test code in CoffeeScript
http = require 'http'
fs = require 'fs'
cluster = require 'cluster'
numCPUs = require('os').cpus().length
if cluster.isMaster
for i in [0..numCPUs-1]
cluster.fork()
cluster.on 'exit', (worker, code, signal) ->
console.log "worker #{worker.process.pid} died"
else
server = http.createServer (request, response) ->
file = parseInt request.url.substring(1)
file = file % 190
file = String("000#{file}").slice(-3)
fs.readFile "../data/input#{file}", 'ascii', (err, data) ->
if err?
response.writeHead 400, {'Content-Type':'text/plain'}
response.end()
else
results = data.toString().split("\r\n")
results.sort()
response.writeHead 200, {'Content-Type': 'text/plain'}
response.end "input#{file}.txt\t#{results[(parseInt(results.length/2))]}"
server.listen 8080, '127.0.0.1'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment