Permalink
Browse files

benchmarks updated

  • Loading branch information...
olegp committed Jun 19, 2011
1 parent 5c11c4e commit eb2c7e177bc119a8d0febd2a4aaf006984d37503
@@ -0,0 +1,13 @@
+var ByteArray = require('binary').ByteArray;
+
+exports.app = function(request) {
+ var n = 1024, b;
+ for (var i = 1; i <= 50; i++)
+ b = new ByteArray(n);
+ return {
+ status: 200,
+ headers: {"Content-Type": "text/plain"},
+ body: [b]
+ };
+}
+
@@ -0,0 +1,11 @@
+var http = require('http');
+var Buffer = require('buffer').Buffer;
+
+http.createServer(function (req, res) {
+ var n = 1024, b;
+ for (var i = 1; i <= 50; i++)
+ b = new Buffer(n);
+ res.writeHead(200, {"Content-Type": "text/plain"});
+ res.end(b);
+}).listen(8080);
+
@@ -0,0 +1,17 @@
+var ByteArray = require('binary').ByteArray;
+
+exports.app = function(request) {
+ var n = 1024, b;
+ for (var i = 1; i <= 50; i++)
+ b = new ByteArray(n);
+ return {
+ status: 200,
+ headers: {"Content-Type": "text/plain"},
+ body: [b]
+ };
+}
+
+if (require.main === module) {
+ require("ringo/httpserver").main(module.id);
+}
+
View
@@ -0,0 +1,80 @@
+#!/usr/bin/env bash
+# based on http://github.com/senchalabs/connect/tree/master/benchmarks/
+
+COL=${COL-9}
+ABFLAGS=$(cat results/flags)
+
+# Log <msg ...>
+#
+# <msg ...>
+#
+
+log(){
+ echo "... $@"
+}
+
+#
+# Output gnuplot script for line graph.
+#
+# <title> <node> <connect>
+#
+
+function line() {
+ cat <<-EOF
+set terminal png # enhanced size 600 380 fname "Sans" fsize 11
+set output "results/graphs/$1.png"
+set title "$2 ($ABFLAGS)"
+# set size 0.97,0.97
+set grid y
+set key left top
+set xlabel "requests"
+set ylabel "response time (ms)"
+plot "$3" using $COL smooth sbezier with lines title "common", \\
+ "$4" using $COL smooth sbezier with lines title "connect", \\
+ "$5" using $COL smooth sbezier with lines title "ringo"
+EOF
+}
+
+#
+# Output gnuplot script for bar graph.
+#
+# <title> <node> <connect>
+#
+
+function bar() {
+cat <<-EOF
+set terminal png
+set output "results/graphs/$1.rps.png"
+set title "$1 $ABFLAGS"
+set size 0.7,0.5
+set grid y
+set key left top
+set ylabel "requests per second"
+plot "$1.rps.dat" using 2: xtic(1) with histogram title ""
+EOF
+}
+
+#
+# Graph the output of the given <dir>.
+#
+# <dir>
+#
+
+function graph(){
+ log graphing $1
+local dir=results/$1
+line $1 "$2" \
+$dir/common-node.dat \
+$dir/node.dat \
+$dir/ringo.dat \
+> results/$1.p
+gnuplot results/$1.p
+}
+
+# Make ./results/graphs
+mkdir -p results/graphs
+
+graph no-alloc "no alloc"
+graph hello "hello world"
+graph static "static file"
+
@@ -0,0 +1,7 @@
+exports.app = function() {
+ return {
+ status : 200,
+ headers : {'Content-Type': 'text/plain'},
+ body : ['Hello World!\n']
+ };
+}
@@ -0,0 +1,12 @@
+require('connect').createServer(function (req, res, next) {
+ res.writeHead(200, {'Content-Type': 'text/plain'});
+ res.end('Hello World!\n');
+}).listen(8080);
+
+/*
+var http = require('http');
+http.createServer(function (req, res) {
+ res.writeHead(200, {'Content-Type': 'text/plain'});
+ res.end('Hello World!\n');
+}).listen(8080);
+*/
@@ -0,0 +1,11 @@
+exports.app = function() {
+ return {
+ status : 200,
+ headers : {'Content-Type': 'text/plain'},
+ body : ['Hello World!\n']
+ };
+}
+
+if (require.main === module) {
+ require("ringo/httpserver").main(module.id);
+}
@@ -0,0 +1,15 @@
+var ByteArray = require('binary').ByteArray;
+
+var n = 1024;
+var b = new ByteArray(n);
+for (var i = 0; i < n; i++)
+ b[i] = 100;
+
+exports.app = function(request) {
+ return {
+ status: 200,
+ headers: {"Content-Type": "text/plain"},
+ body: [b]
+ };
+}
+
@@ -0,0 +1,13 @@
+var http = require('http');
+var Buffer = require('buffer').Buffer;
+
+var n = 1024;
+var b = new Buffer(n);
+for (var i = 0; i < n; i++)
+ b[i] = 100;
+
+http.createServer(function (req, res) {
+ res.writeHead(200, {"Content-Type": "text/plain"});
+ res.end(b);
+}).listen(8080);
+
@@ -0,0 +1,19 @@
+var ByteArray = require('binary').ByteArray;
+
+var n = 1024;
+var b = new ByteArray(n);
+for (var i = 0; i < n; i++)
+ b[i] = 100;
+
+exports.app = function(request) {
+ return {
+ status: 200,
+ headers: {"Content-Type": "text/plain"},
+ body: [b]
+ };
+}
+
+if (require.main === module) {
+ require("ringo/httpserver").main(module.id);
+}
+
@@ -0,0 +1,13 @@
+var json = require('./common').json;
+
+exports.app = function(request) {
+ JSON.parse(json);
+ return {
+ status: 200,
+ headers: {"Content-Type": "text/plain"},
+ body: [json]
+ };
+}
+
+
+
@@ -0,0 +1,14 @@
+//
+var json = '';
+for (var i = 0; i < 100; i++) {
+ json += '"outer' + i +'":{';
+ for (var j = 0; j < 10; j++) {
+ json += '"inner' + j + '":"123456789' + i + '"';
+ if (j < 9) json += ','
+ }
+ json += '}';
+ if (i < 99) json += ','
+}
+
+exports.json = '{' + json + '}';
+
@@ -0,0 +1,10 @@
+var http = require('http');
+var json = require('./common').json;
+var jsonBuffer = new Buffer(json);
+
+http.createServer(function (req, res) {
+ JSON.parse(json);
+ res.writeHead(200, {"Content-Type": "text/plain"});
+ res.end(jsonBuffer);
+}).listen(8080);
+
@@ -0,0 +1,15 @@
+var json = require('./common').json;
+
+exports.app = function(request) {
+ JSON.parse(json);
+ return {
+ status: 200,
+ headers: {"Content-Type": "text/plain"},
+ body: [json]
+ };
+}
+
+if (require.main === module) {
+ require("ringo/httpserver").main(module.id);
+}
+
View
@@ -0,0 +1,65 @@
+#!/usr/bin/env bash
+# based on http://github.com/senchalabs/connect/tree/master/benchmarks/
+
+ABFLAGS=${ABFLAGS-"-n 50000 -c 50"}
+ADDR=${ADDR-http://0.0.0.0:8080/}
+AB=${AB-ab}
+
+#
+# Log <msg ...>
+#
+# <msg ...>
+#
+
+log(){
+ echo "... $@"
+}
+
+#
+# Benchmark the given <dir> and [path].
+#
+# <dir> [path]
+#
+
+bm(){
+ local dir=$1;
+ for platform in common-node node ringo
+ do
+ local flags=""
+ if [ $platform = "ringo" ]; then
+ # disable module reloading on ringo
+ flags="-p"
+ fi
+ $platform $flags $dir/$platform.js &
+ local pid=$!
+ sleep 2
+ local dirname=results/$dir
+ mkdir -p $dirname
+ # jvm needs warmup time to reach final speed. If you run smaller
+ # batches you'll need more runs for warmup.
+ for runs in {1..2}
+ do
+ $AB $ABFLAGS -g $dirname/$platform.dat $ADDR/$path > $dirname/$platform.out
+ sleep 1
+ done
+ log $(cat $dirname/$platform.out | grep Requests)
+ kill $pid
+ sleep 2
+ done
+}
+
+# Make ./results
+mkdir -p results
+
+# Store flags
+echo "$ABFLAGS" > results/flags
+
+# Run benchmarks
+log $AB $ABFLAGS $ADDR
+bm buffer-alloc
+bm hello-world
+bm no-alloc
+bm parse-json
+bm static-file /README.md
+bm string-alloc
+
@@ -0,0 +1,12 @@
+var openRaw = require('fs-base').openRaw;
+exports.app = function() {
+ return {
+ status: 200,
+ headers: {'Content-Type': 'text/plain'},
+ body: openRaw('../README.md')
+ };
+}
+
+if (require.main === module) {
+ require("ringo/httpserver").main(module.id);
+}
@@ -0,0 +1,5 @@
+var connect = require('connect');
+
+connect(
+ connect.static('../')
+).listen(8080);
@@ -0,0 +1,12 @@
+var openRaw = require('fs').openRaw;
+exports.app = function() {
+ return {
+ status: 200,
+ headers: {'Content-Type': 'text/plain'},
+ body: openRaw('../README.md')
+ };
+}
+
+if (require.main === module) {
+ require("ringo/httpserver").main(module.id);
+}
@@ -0,0 +1,17 @@
+var ByteArray = require('binary').ByteArray;
+
+var n = 1024;
+var b = new ByteArray(n);
+for (var i = 0; i < n; i++)
+ b[i] = 100;
+
+exports.app = function(request) {
+ for (var i = 1; i <= 50; i++)
+ b.decodeToString("ascii");
+ return {
+ status: 200,
+ headers: {"Content-Type": "text/plain"},
+ body: [b]
+ };
+}
+
@@ -0,0 +1,15 @@
+var http = require('http');
+var Buffer = require('buffer').Buffer;
+
+var n = 1024;
+var b = new Buffer(n);
+for (var i = 0; i < n; i++)
+ b[i] = 100;
+
+http.createServer(function (req, res) {
+ for (var i = 1; i <= 50; i++)
+ b.toString("ascii");
+ res.writeHead(200, {"Content-Type": "text/plain"});
+ res.end(b);
+}).listen(8001);
+
Oops, something went wrong.

0 comments on commit eb2c7e1

Please sign in to comment.