Permalink
Browse files

Added benchmarking

  • Loading branch information...
1 parent 7a7b84c commit 068f5b2fd27670aa7d2f911fee471344b51556af @balupton balupton committed Oct 29, 2012
Showing with 107 additions and 1 deletion.
  1. +4 −1 Makefile
  2. +60 −0 out/test/benchmark.js
  3. +43 −0 src/test/benchmark.coffee
View
@@ -4,10 +4,13 @@ compile:
dev:
./node_modules/.bin/coffee -w -o out/ -c src/
+bench:
+ node ./out/test/benchmark.js
+
test:
node ./out/test/everything.test.js --joe-reporter=list
test-debug:
node --debug-brk ./out/test/everything.test.js
-.PHONY: compile dev test test-debug
+.PHONY: compile dev bench test test-debug
View
Oops, something went wrong.
@@ -0,0 +1,43 @@
+queryEngine = require?(__dirname+'/../lib/query-engine.js') or @queryEngine
+Benchmark = require('benchmark')
+
+console.log('Benchmarking...')
+suite = new Benchmark.Suite()
+
+models = []
+for i in [0..1000]
+ models.push(
+ name: "Name #{i}"
+ description: Math.random()
+ second: !!(i % 2)
+ third: !!(i % 3)
+ )
+collection = new queryEngine.QueryCollection(models)
+
+suite.add '$or', ->
+ collection.findAll({
+ $or: [
+ {second: true},
+ {third: true}
+ ]
+ })
+
+suite.add '$and', ->
+ collection.findAll({
+ second: true
+ third: true
+ })
+
+suite.add '$and - one', ->
+ collection.findOne({
+ second: true
+ third: true
+ })
+
+suite
+ .on 'cycle', (event) ->
+ console.log(String(event.target))
+ .on 'complete', ->
+ console.log('Fastest is ' + this.filter('fastest').pluck('name'))
+
+suite.run()

0 comments on commit 068f5b2

Please sign in to comment.