Permalink
Browse files

benchmark

  • Loading branch information...
1 parent 35a2479 commit c2645a8a80dc99771f23cacb1239cf35090d39aa @snakajima committed Nov 25, 2012
Showing with 52 additions and 2 deletions.
  1. +6 −1 test/server.js
  2. +32 −0 test/socket.js
  3. +6 −1 test/web/main.js
  4. +8 −0 test/web/socket.html
View
@@ -13,16 +13,21 @@ function handler(request, response) {
});
}
+
comet.on('connection', function (socket) {
console.log('connected...patient');
+ var total_time = 0;
+ var start_time = new Date();
socket.emit('test.message', { count:0 });
socket.on('test.response', function(data) {
+ total_time += new Date() - start_time;
if (data.count++ < 100) {
setTimeout(function() {
+ start_time = new Date();
socket.emit('test.message', { count:data.count });
}, 10);
} else {
- console.log('success');
+ console.log('success', total_time);
}
});
});
View
@@ -0,0 +1,32 @@
+var app = require('http').createServer(handler);
+var file = new(require('node-static').Server)(__dirname + '/web', {});
+var io = require('socket.io').listen(app);
+
+app.listen(8000);
+function handler(request, response) {
+ request.on('end', function() {
+ file.serve(request, response, function(err, res) {
+ //if (err) { console.log(err); }
+ });
+ });
+}
+
+io.on('connection', function (socket) {
+ console.log('connected...patient');
+ var total_time = 0;
+ var start_time = new Date();
+ socket.emit('test.message', { count:0 });
+ socket.on('test.response', function(data) {
+ total_time += new Date() - start_time;
+ if (data.count++ < 100) {
+ setTimeout(function() {
+ start_time = new Date();
+ socket.emit('test.message', { count:data.count });
+ }, 10);
+ } else {
+ console.log('success', total_time);
+ }
+ });
+});
+
+console.log('Access http://localhost:8000/socket.html with your browser to run test.');
View
@@ -1,5 +1,10 @@
$(document).ready(function() {
- var socket = comet.connect();
+ var socket;
+ if (typeof io == 'undefined') {
+ socket = comet.connect();
+ } else {
+ socket = io.connect();
+ }
socket.on('connect', function() {
console.log('connected');
}).on('test.message', function (data) {
View
@@ -0,0 +1,8 @@
+<HTML>
+ <head>
+ <script src="/jquery-1.8.2.js"></script>
+ <script src="/socket.io/socket.io.js"></script>
+ <script src="/main.js"></script>
+ </head>
+ <BODY>Hello</BODY>
+</HTML>

0 comments on commit c2645a8

Please sign in to comment.