Ticket #1077: test_all_sites_time.coffee

File test_all_sites_time.coffee, 664 bytes (added by capedfuzz, 2 years ago)

A quick benchmark used to test how long it takes to retrieve the All Websites HTML. Written in CoffeeScript & uses node.js.

Line 
1querystring = require 'querystring'
2http = require 'http'
3fs = require 'fs'
4
5url = 'http://localhost/index.php?module=MultiSites&action=index&idSite=1&period=day&date=2011-11-1'
6
7start_time = (new Date()).getTime()
8
9r = http.request {host: 'localhost', port: 80, path: url, method: 'GET'}, (res) ->
10  body = ''
11  res.on 'data', (chunk) -> body += chunk
12  res.on 'end', () ->
13    if res.statusCode == 200
14      end_time = (new Date()).getTime()
15      elapsed = end_time - start_time
16   
17      console.log "Elapsed time: #{ elapsed / 1000.0 }s"
18    else
19      console.log "ERROR: Got status '#{ res.statusCode }'"
20    fs.writeFileSync('output.html', body)
21r.end()
22