Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ test-report:
--reporter markdown \
test/unit > ./test-unit.md

test-perf:
@NODE_ENV=test ./node_modules/.bin/mocha $(T) \
--compilers coffee:coffee-script \
--recursive \
--reporter $(REPORTER) \
--timeout 5000 \
test/perf

.PHONY: test test-report
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
, "moment": "2.1.0"
},
"devDependencies": {
"should": "1.2.2"
, "sinon": "v1.7.3"
"sinon": "v1.7.3"
, "mocha": "1.12.1"
, "async": "0.2.5"
, "coffee-script": "1.5.0"
, "memwatch": "v0.2.2"
, "winston": "v0.7.3"
, "chalk": "v0.4.0"
},
"keywords": [
"nodeJs"
Expand Down
4 changes: 4 additions & 0 deletions test/bootstrap-perf.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mongoose = require 'mongoose'

mongoose.connect "mongodb://127.0.0.1:27017/mongoose-rattle-test-perf", {}, (err) ->
throw err if err
86 changes: 86 additions & 0 deletions test/perf-data.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
require './bootstrap-perf'

mongoose = require 'mongoose'
async = require 'async'
winston = require 'winston'

winston.remove winston.transports.Console
winston.add winston.transports.Console, colorize: true

Thingy = require './models/thingy'

ObjectId = mongoose.Types.ObjectId;

numThingies = 5
numLikes = 20000
numCommentLikes = 20
blockNumComments = 5000
numBlocks = 4

i = 0
likes = []
while i < numCommentLikes
likes.push new ObjectId()
i++

dummyComment =
message: 'duuuuuuuuuuuummmmmmmmmmmmmmmmyyyyyyyyyyyyy meeeeeeeeeeeeessssssssssssaaaaaaaaaaaaaageeeeee'
creator: new ObjectId()
likes: likes
likesCount: type: Number, default: 0
dateCreation: type: Date
dateUpdate: type: Date

i = 0
comments = []
while i < blockNumComments
comments.push dummyComment
i++

createNewThingy = (callback) ->
async.waterfall [
createThingy = (next) ->
winston.info('Create a new thingy');
new Thingy(
creator: new ObjectId()
).save next
addComments = (createdThingy, numAffected, next) ->
winston.info('Add comments with likes');

i = 0
async.whilst (->
i < numBlocks
), ((callback) ->
winston.info('Add block ' + (i + 1) + ' of ' + blockNumComments + ' comments');
Thingy.update { _id: createdThingy._id }, { $pushAll: { comments: comments } }, (err) ->
i++
callback()
), (err) ->
winston.info('Add likes');
i = 0
likes = []
while i < numLikes
likes.push new ObjectId()
i++
createdThingy.likes = likes
createdThingy.save next

], (err) ->
return callback(err) if err
winston.info('Thingy saved');
callback()


winston.info('Clear thingy collection');
Thingy.remove (err) ->
count = 0
async.whilst (->
count < numThingies
), ((next) ->
createNewThingy (err) ->
return next(err) if err
count++
next()
), (err) ->
winston.error err if err
process.exit(1);
78 changes: 78 additions & 0 deletions test/perf-stats.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
require './bootstrap-perf'

mongoose = require 'mongoose'
async = require 'async'
memwatch = require 'memwatch'
chalk = require 'chalk'

log = (level, msg) ->
console.log(Array(level).join(' ') + msg)
title = (msg) ->
log(1, chalk.bold.magenta.underline(msg))
description = (msg) ->
log(1, chalk.bold.italic(msg))
target = (msg) ->
log(2, chalk.green(msg))
info = (msg) ->
log(4, chalk.blue(msg))

Thingy = require './models/thingy'

numOccurence = 3

# hd = new memwatch.HeapDiff()
# diff = hd.end()
# log.info('memory diff after the operation (in bytes): ' + diff.change.size_bytes)

task = () ->
msg = arguments[0]
obj = arguments[1]
fctName = arguments[2]
args = Array::slice.call(arguments, 3, arguments.length - 1)
callback = arguments[arguments.length - 1]

log(3, chalk.yellow(msg))
count = 1
totalTime = 0
async.whilst (->
count <= numOccurence
), ((next) ->
start = Date.now()

cb = (err) ->
return next(err) if err
end = Date.now()
time = end - start
totalTime += time
info("[iteration #{count}] time for the operation (in ms): #{time}")
count++
next()

fctArgs = args.slice(0)
fctArgs.push(cb)
obj[fctName].apply obj, fctArgs
return
), (err) ->
return callback(err) if err
avg = Math.ceil(totalTime / numOccurence)
info("=> average time: #{avg}")
callback()

title("Benchmarking rattle plugin (number of occurence: #{numOccurence})")
description('In collections: 2 documents with 20000 likes, 20000 comments with 20 likes each')

# describe 'Thingy', ->
# describe 'getList', ->
# analyse('retrieve 2 documents with no comments', Thingy, 'getList', 2, 0, next)
# analyse('retrieve 3 documents with the last 5 comments', Thingy, 'getList', 3, 5, next)

async.series [
getList = (done) ->
target('#getList')
async.series [
(next) ->
task('retrieve two documents with no comments', Thingy, 'getList', 2, 0, next)
], done

], (err) ->
process.exit(1);
Loading