Skip to content
Browse files

benchmarks updated

  • Loading branch information...
1 parent 5c11c4e commit eb2c7e177bc119a8d0febd2a4aaf006984d37503 @olegp committed
View
13 benchmarks/buffer-alloc/common-node.js
@@ -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]
+ };
+}
+
View
11 benchmarks/buffer-alloc/node.js
@@ -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);
+
View
17 benchmarks/buffer-alloc/ringo.js
@@ -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
80 benchmarks/graph
@@ -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"
+
View
7 benchmarks/hello-world/common-node.js
@@ -0,0 +1,7 @@
+exports.app = function() {
+ return {
+ status : 200,
+ headers : {'Content-Type': 'text/plain'},
+ body : ['Hello World!\n']
+ };
+}
View
12 benchmarks/hello-world/node.js
@@ -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);
+*/
View
11 benchmarks/hello-world/ringo.js
@@ -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);
+}
View
15 benchmarks/no-alloc/common-node.js
@@ -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]
+ };
+}
+
View
13 benchmarks/no-alloc/node.js
@@ -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);
+
View
19 benchmarks/no-alloc/ringo.js
@@ -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);
+}
+
View
13 benchmarks/parse-json/common-node.js
@@ -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]
+ };
+}
+
+
+
View
14 benchmarks/parse-json/common.js
@@ -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 + '}';
+
View
10 benchmarks/parse-json/node.js
@@ -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);
+
View
15 benchmarks/parse-json/ringo.js
@@ -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
65 benchmarks/run
@@ -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
+
View
12 benchmarks/static-file/common-node.js
@@ -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);
+}
View
5 benchmarks/static-file/node.js
@@ -0,0 +1,5 @@
+var connect = require('connect');
+
+connect(
+ connect.static('../')
+).listen(8080);
View
12 benchmarks/static-file/ringo.js
@@ -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);
+}
View
17 benchmarks/string-alloc/common-node.js
@@ -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]
+ };
+}
+
View
15 benchmarks/string-alloc/node.js
@@ -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);
+
View
21 benchmarks/string-alloc/ringo.js
@@ -0,0 +1,21 @@
+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]
+ };
+}
+
+if (require.main === module) {
+ require("ringo/httpserver").main(module.id);
+}
+
View
3 bin/common-node
@@ -8,7 +8,8 @@ if(process.argv.length < 2) {
var path = require('path');
var lib = path.resolve(path.dirname(module.filename), '../lib/');
require.paths.push(lib);
- require('system').spawn(function() {
+ require('global');
+ spawn(function() {
var main = require(path.resolve(process.cwd(), process.argv[1]));
if(main.app) {
require('jsgi').run(main.app, process.argv[2] || 8080);
View
2 lib/all.js
@@ -1,5 +1,5 @@
var modules = ['assert', 'binary', 'fs-base', 'httpclient',
- 'io', 'jsgi', 'system', 'test'];
+ 'io', 'jsgi', 'system', 'test', 'global'];
for(var i = 0; i < modules.length; i ++) {
exports[modules[i]] = require('./' + modules[i]);
View
48 lib/global.js
@@ -0,0 +1,48 @@
+/**
+ * @fileoverview Provides global functions
+ * import, include, export and spawn for RingoJS compatibility.</p>
+ */
+
+/**
+ * Load a module and include all its properties in the calling scope.
+ * @param {String} moduleName the module name such as 'core.object'
+ */
+global.include = exports.include = function(moduleName) {
+ var module = this.require(moduleName);
+ for (var key in module) {
+ this[key] = module[key];
+ }
+}
+
+/**
+ * Define the properties to be exported.
+ * @param name one or more names of exported properties
+ */
+global.export = exports.export = function() {
+ var module = this;
+ var exports = this.exports;
+ if (!exports || typeof exports != "object") {
+ // this should never happen
+ exports = {};
+ Object.defineProperty(module, "exports", { value: exports });
+ }
+ Array.forEach(arguments, function(name) {
+ Object.defineProperty(exports, name, {
+ get: function() {
+ return module[name];
+ },
+ enumerable: true
+ });
+ });
+}
+
+// preload system module
+var system = global.system = require('system');
+
+/**
+ * spawn() from the system module. Spawns a new thread.
+ * @param {Function} run entry point of the new thread.
+ */
+global.spawn = exports.spawn = system.spawn;
+
+//TODO add getResource
View
28 tools/jsdoc/hosted.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html >
+
+<html lang="de" dir="ltr">
+<head>
+ <title>{{title}}</title>
+ <link rel="shortcut icon" href="http://ringojs.org/favicon.ico" type="image/x-icon" />
+ <link rel="icon" href="http://ringojs.org/favicon.ico" type="image/x-icon" />
+ <link rel="stylesheet" href="{{rootPath}}static/style.css" />
+ {{{head}}}
+</head>
+
+<body>
+<div class="wrap">
+{{{content}}}
+ <div class="menu" style="margin-top: 1em; font-size: 13px;">
+ <p>
+ <a class="repositoryname" href="{{rootPath}}{{indexhtml}}">{{repositoryName}} </a>
+ </p>
+
+ {{{menu}}}
+</div>
+</div>
+</body>
+</html>
+
+
+
+
View
102 tools/jsdoc/jsdoc.css
@@ -0,0 +1,102 @@
+pre.code {
+ background-color: #abc;
+ border-width: 1px;
+ border-color: #9ab;
+ border-style: solid;
+ padding: 0.8em;
+ line-height: 145%;
+}
+
+table td {
+ vertical-align: top;
+ padding: 0 10px;
+}
+
+h4 {
+ margin: 5px 0;
+ color: green;
+ font-weight: bold;
+}
+
+.dimmed {
+ color: #333;
+ font-weight: 500;
+}
+
+.paramname {
+ font-weight:bold;
+}
+
+.extrainfo {
+ padding:0 12px;
+}
+
+.leftnav, .repositorylist, .propertyoverview {
+ list-style-type: none;
+ padding: 2px;
+}
+
+.docitem {
+}
+
+.docitem .itemtitle {
+ font-size:large;
+ text-decoration:none;
+}
+
+.light {
+ font-weight: normal;
+}
+
+.docitem.highlight {
+ border-left: 4px solid green;
+ padding: 0 0 0 6px;
+}
+
+ul.modulelist {
+ list-style-type:none;
+ margin: 0;
+ padding-left: 10px;
+}
+
+.repositoryname {
+ font-weight:bold;
+}
+
+.moduleheader {
+ padding: 8px;
+}
+
+h2, h3 {
+ margin-bottom: 5px;
+}
+
+h3 {
+ font-size: small;
+}
+
+ul {
+ margin: 5px;
+}
+
+hr {
+ border: 0;
+ color: #999;
+ background-color: #999;
+ height: 1px;
+}
+
+.classoverview {
+ /* background-color: #f0ffc0; #f7ffe5; */
+ padding: 5px 10px;
+ margin: 15px 0;
+}
+
+.modulename {
+ /* background-color: #f1ffcc; */
+}
+
+.showmore {
+ color: blue;
+ cursor: pointer;
+}
View
28 tools/jsdoc/static.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html >
+
+<html lang="de" dir="ltr">
+<head>
+ <title>{{title}}</title>
+ <link rel="shortcut icon" href="http://ringojs.org/favicon.ico" type="image/x-icon" />
+ <link rel="icon" href="http://ringojs.org/favicon.ico" type="image/x-icon" />
+ <link rel="stylesheet" href="{{rootPath}}static/style.css" />
+ {{{head}}}
+</head>
+
+<body>
+<div class="wrap">
+{{{content}}}
+ <div class="menu" style="margin-top: 1em; font-size: 13px;">
+ <p>
+ <a class="repositoryname" href="{{rootPath}}{{indexhtml}}">{{repositoryName}} </a>
+ </p>
+
+ {{{menu}}}
+</div>
+</div>
+</body>
+</html>
+
+
+
+
View
46 tools/jsdoc/style.css
@@ -0,0 +1,46 @@
+body, html {
+ margin: 0;
+ padding: 0;
+}
+
+body {
+ min-width: 850px;
+ font-family: sans-serif;
+ font-size: 80%;
+ line-height: 170%;
+ color: #EEEEEE;
+ background: none repeat scroll 0 0 #22252A;
+}
+
+a {
+ color: #CCDD55;
+ text-decoration: none;
+}
+
+h1 {
+ padding: 14px 0;
+}
+
+div.wrap {
+ margin: 0 auto;
+ width: 800px;
+}
+
+div.main {
+ clear: both;
+ float: left;
+ width: 530px;
+ margin: 0 10px;
+ padding: 5px;
+}
+
+div.menu {
+ float: right;
+ padding-top: 6em;
+}
+
+.hidden {
+ visibility:hidden;
+ display:none;
+}
+

0 comments on commit eb2c7e1

Please sign in to comment.
Something went wrong with that request. Please try again.