Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adds a benchmark for cache vs. no cache.

  • Loading branch information...
commit b0e105be1091315488550a2dfe781127d35921d5 1 parent 1eff17a
@cpsubrian authored
View
21 Makefile
@@ -2,4 +2,23 @@ test:
@./node_modules/.bin/mocha \
--reporter spec
-.PHONY: test
+bench: install-bench bench-caching
+
+check = \
+ if [ -z `which siege` ]; then \
+ echo "please install siege. http://www.joedog.org/siege-home/"; \
+ exit 1; \
+ fi
+
+install-bench:
+ @$(call check)
+ @npm install
+ @cd bench; npm install
+
+bench-caching: install-bench
+ @./node_modules/.bin/benchmarx \
+ --title "views caching" \
+ --runner siege \
+ bench/*.js
+
+.PHONY: test bench
View
27 bench/README.md
@@ -0,0 +1,27 @@
+views-benchmarks
+================
+
+Benchmarks cache vs. no-cache
+
+Usage
+-----
+
+In the views root, run:
+
+```bash
+$ make bench
+```
+
+My results
+----------
+
+For handlebars, no improvement ... warrants research. Perhaps handlebars already
+caches?
+
+```
+SUMMARY
+-------
+
+**************** with-cache (545.49 rps)
+**************** no-cache (542.53 rps)
+```
View
24 bench/no-cache.js
@@ -0,0 +1,24 @@
+var middler = require('middler'),
+ http = require('http'),
+ views = require('../'),
+ server;
+
+exports.version = require(require('path').resolve(__dirname, '../package.json')).version;
+
+exports.listen = function(options, cb) {
+ server = http.createServer();
+
+ middler(server)
+ .add(views.middleware(__dirname + '/views'))
+ .add(function(req, res, next) {
+ res.render('index', {title: 'Views benchmark - no cache'});
+ });
+
+ server.listen(0, function() {
+ cb(null, server.address().port);
+ });
+};
+
+exports.close = function() {
+ server.close();
+};
View
8 bench/package.json
@@ -0,0 +1,8 @@
+{
+ "name": "views-benchmarks",
+ "version": "0.0.0",
+ "private": true,
+ "dependencies": {
+ "middler": "0.4.7"
+ }
+}
View
2  bench/views/index.hbs
@@ -0,0 +1,2 @@
+<h1>{{title}}</h1>
+Hey, this is a benchmark.
View
4 bench/views/layout.hbs
@@ -0,0 +1,4 @@
+<html>
+ <head></head>
+ <body>{{{content}}}</body>
+</html>
View
24 bench/with-cache.js
@@ -0,0 +1,24 @@
+var middler = require('middler'),
+ http = require('http'),
+ views = require('../'),
+ server;
+
+exports.version = require(require('path').resolve(__dirname, '../package.json')).version;
+
+exports.listen = function(options, cb) {
+ server = http.createServer();
+
+ middler(server)
+ .add(views.middleware(__dirname + '/views', {cache: true}))
+ .add(function(req, res, next) {
+ res.render('index', {title: 'Views benchmark - no cache'});
+ });
+
+ server.listen(0, function() {
+ cb(null, server.address().port);
+ });
+};
+
+exports.close = function() {
+ server.close();
+};
View
3  package.json
@@ -21,7 +21,8 @@
"devDependencies": {
"mocha": "~1.4.0",
"request": "~2.10.0",
- "handlebars": "~1.0.6-2"
+ "handlebars": "~1.0.6-2",
+ "benchmarx": "~0.2.2"
},
"keywords": [
"views", "templates", "render", "partials"
Please sign in to comment.
Something went wrong with that request. Please try again.