Remove process.mixin dependencies from benchmark scripts
[platform/upstream/nodejs.git] / benchmark / http_simple.js
1 path = require("path");
2
3 libDir = path.join(path.dirname(__filename), "../lib");
4 require.paths.unshift(libDir);
5
6 var sys = (require("sys"));
7 for (var i in sys) global[i] = sys[i];
8 http = require("http");
9
10 fixed = ""
11 for (var i = 0; i < 20*1024; i++) {
12   fixed += "C";
13 }
14
15 stored = {};
16
17 http.createServer(function (req, res) {
18   var commands = req.url.split("/");
19   var command = commands[1];
20   var body = "";
21   var arg = commands[2];
22   var status = 200;
23
24   if (command == "bytes") {
25     var n = parseInt(arg, 10)
26     if (n <= 0)
27       throw "bytes called with n <= 0" 
28     if (stored[n] === undefined) {
29       puts("create stored[n]");
30       stored[n] = "";
31       for (var i = 0; i < n; i++) {
32         stored[n] += "C"
33       }
34     }
35     body = stored[n];
36
37   } else if (command == "quit") {
38     res.connection.server.close();
39     body = "quitting";
40
41   } else if (command == "fixed") {
42     body = fixed;
43
44   } else {
45     status = 404;
46     body = "not found\n";
47   }
48
49   var content_length = body.length.toString();
50
51   res.writeHead( status 
52                 , { "Content-Type": "text/plain"
53                   , "Content-Length": content_length
54                   }
55                 );
56   res.write(body);
57   res.close();
58 }).listen(8000);