Skip to content

Node.js based forum software built for the modern web

for loop bench in testbed

Baris Soner Usakli399f7b47c880
diff --git a/src/routes/testbed.js b/src/routes/testbed.js
new file mode 100644
index 0000000000..2abc87fe60
--- /dev/null
+++ b/src/routes/testbed.js
@@ -0,0 +1,63 @@
+
+
+(function(TestBed) {
+ TestBed.create_routes = function(app) {
+
+ app.get('/bench/forloop', function(req, res) {
+ var benchData = {};
+
+ var myArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
+
+ function f(x) {
+ return x;
+ }
+
+ var runCount = req.query.runs ? req.query.runs : 1000000;
+
+ function withCaching() {
+ var time = process.hrtime();
+
+ for(var n=0; n<runCount; ++n) {
+ for (var i = 0, len = myArray.length; i < len; ++i) {
+ f(myArray[i]);
+ }
+ }
+
+ var diff = process.hrtime(time);
+ diff = diff[0] + diff[1] / 1e9;
+ return diff;
+ }
+
+ function withoutCaching() {
+ var time = process.hrtime();
+
+ for(var n=0; n<runCount; ++n) {
+ for (var i = 0; i < myArray.length; ++i) {
+ f(myArray[i]);
+ }
+ }
+
+ var diff = process.hrtime(time);
+ diff = diff[0] + diff[1] / 1e9;
+ return diff;
+
+ }
+
+ benchData['runs'] = runCount;
+
+ benchData['withCaching'] = withCaching();
+ benchData['withoutCaching'] = withoutCaching();
+
+ res.json(benchData);
+
+
+ });
+
+
+
+
+
+ };
+
+
+}(exports));
\ No newline at end of file
diff --git a/src/webserver.js b/src/webserver.js
index 6cc54ec353..943dece478 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -17,6 +17,7 @@ var express = require('express'),
admin = require('./routes/admin.js'),
userRoute = require('./routes/user.js'),
installRoute = require('./routes/install.js'),
+ testBed = require('./routes/testbed.js'),
auth = require('./routes/authentication.js'),
meta = require('./meta.js');
@@ -76,7 +77,7 @@ var express = require('express'),
admin.create_routes(app);
userRoute.create_routes(app);
installRoute.create_routes(app);
-
+ testBed.create_routes(app);
app.create_route = function(url, tpl) { // to remove
return '<script>templates.ready(function(){ajaxify.go("' + url + '", null, "' + tpl + '");});</script>';