summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorRyan <ry@tinyclouds.org>2009-06-18 14:36:30 +0200
committerRyan <ry@tinyclouds.org>2009-06-18 14:36:30 +0200
commit61fcbb1cd6947a21d92c109991451bfb4a3f5e20 (patch)
tree7e40b38072594ec7b1dd2dd4273ae94a549ecec9 /benchmark
parente30e4415eedfb7f97db5de0490b64f01e0f1d5fe (diff)
downloadnode-new-61fcbb1cd6947a21d92c109991451bfb4a3f5e20.tar.gz
Add benchmark dir with ruby script
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/http_simple.js50
-rw-r--r--benchmark/http_simple.rb95
2 files changed, 145 insertions, 0 deletions
diff --git a/benchmark/http_simple.js b/benchmark/http_simple.js
new file mode 100644
index 0000000000..2e3bbb3cad
--- /dev/null
+++ b/benchmark/http_simple.js
@@ -0,0 +1,50 @@
+fixed = ""
+for (var i = 0; i < 20*1024; i++) {
+ fixed += "C";
+}
+stored = {};
+new node.http.Server(function (req, res) {
+ var commands = req.uri.path.split("/");
+ var command = commands[1];
+ var body = "";
+ var arg = commands[2];
+ var status = 200;
+
+ //p(req.headers);
+
+ if (command == "bytes") {
+ var n = parseInt(arg, 10)
+ if (n <= 0)
+ throw "bytes called with n <= 0"
+ if (stored[n] === undefined) {
+ puts("create stored[n]");
+ stored[n] = "";
+ for (var i = 0; i < n; i++) {
+ stored[n] += "C"
+ }
+ }
+ body = stored[n];
+
+ } else if (command == "quit") {
+ res.connection.server.close();
+ body = "quitting";
+
+ } else if (command == "fixed") {
+ body = fixed;
+
+ } else {
+ status = 404;
+ body = "not found\n";
+ }
+
+ var content_length = body.length.toString();
+
+ res.sendHeader( status
+ , [ ["Content-Type", "text/plain"]
+ , ["Content-Length", content_length]
+ ]
+ );
+ res.sendBody(body);
+
+ res.finish();
+}).listen(8000);
diff --git a/benchmark/http_simple.rb b/benchmark/http_simple.rb
new file mode 100644
index 0000000000..ee33f57f1d
--- /dev/null
+++ b/benchmark/http_simple.rb
@@ -0,0 +1,95 @@
+DIR = File.dirname(__FILE__)
+
+def fib(n)
+ return 1 if n <= 1
+ fib(n-1) + fib(n-2)
+end
+
+def wait(seconds)
+ n = (seconds / 0.01).to_i
+ n.times do
+ sleep(0.01)
+ #File.read(DIR + '/yahoo.html')
+ end
+end
+
+class SimpleApp
+ @@responses = {}
+
+ def initialize
+ @count = 0
+ end
+
+ def deferred?(env)
+ false
+ end
+
+ def call(env)
+ path = env['PATH_INFO'] || env['REQUEST_URI']
+ commands = path.split('/')
+
+ @count += 1
+ if commands.include?('periodical_activity') and @count % 10 != 1
+ return [200, {'Content-Type'=>'text/plain'}, "quick response!\r\n"]
+ end
+
+ if commands.include?('fibonacci')
+ n = commands.last.to_i
+ raise "fibonacci called with n <= 0" if n <= 0
+ body = (1..n).to_a.map { |i| fib(i).to_s }.join(' ')
+ status = 200
+
+ elsif commands.include?('wait')
+ n = commands.last.to_f
+ raise "wait called with n <= 0" if n <= 0
+ wait(n)
+ body = "waited about #{n} seconds"
+ status = 200
+
+ elsif commands.include?('bytes')
+ n = commands.last.to_i
+ raise "bytes called with n <= 0" if n <= 0
+ body = @@responses[n] || "C"*n
+ status = 200
+
+ elsif commands.include?('fixed')
+ n = 20 * 1024;
+ body = @@responses[n] || "C"*n
+ status = 200
+
+ elsif commands.include?('test_post_length')
+ input_body = ""
+ while chunk = env['rack.input'].read(512)
+ input_body << chunk
+ end
+ if env['CONTENT_LENGTH'].to_i == input_body.length
+ body = "Content-Length matches input length"
+ status = 200
+ else
+ body = "Content-Length doesn't matches input length!
+ content_length = #{env['CONTENT_LENGTH'].to_i}
+ input_body.length = #{input_body.length}"
+ status = 500
+ end
+ else
+ status = 404
+ body = "Undefined url"
+ end
+
+ body += "\r\n"
+ headers = {'Content-Type' => 'text/plain', 'Content-Length' => body.length.to_s }
+ [status, headers, [body]]
+ end
+end
+
+
+if $0 == __FILE__
+ #require DIR + '/../lib/ebb'
+ require 'rubygems'
+ require 'rack'
+ require 'thin'
+ require 'ebb'
+# Rack::Handler::Mongrel.run(SimpleApp.new, :Port => 8000)
+ Thin::Server.start("0.0.0.0", 8000, SimpleApp.new)
+# Ebb::start_server(SimpleApp.new, :port => 8000)
+end