Skip to content

Commit

Permalink
add complex relationship-test
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanpenner committed Nov 28, 2014
1 parent a325c65 commit dd1b773
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 20 deletions.
2 changes: 2 additions & 0 deletions benchmarks/micro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Future plan is to generate these index files more dynamically, for more granular
todo:
-----

- [ ] better on-disk format
- [ ] more convention
- [ ] stats via automated commandline tool
- [ ] more tests
- [ ] make it nicer
Expand Down
29 changes: 9 additions & 20 deletions benchmarks/micro/index.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,29 @@
require('./runner')(
{
distribution: [0, 1, 5],
name: 'create',
distribution: [0, 5, 20],
name: 'pushPayload',
suites: [
require('./create/create-object'),
require('./create/create-record')
require('./push-payload/push-payload')
]
}
);

require('./runner')(
{
distribution: [0],
name: 'buildRecord',
suites: [
require('./build/build-record')
]
}
);

require('./runner')(
{
distribution: [0, 1, 5],
name: 'pushPayload',
distribution: [0, 5, 20],
name: 'pushPayload simple-relationship',
suites: [
require('./push-payload/push-payload')
require('./push-payload-relationships/push-payload')
]
}
);

require('./runner')(
{
distribution: [0, 5, 100],
name: 'pushPayload simple-relationship',
distribution: [0, 5, 20],
name: 'pushPayload self-relationship',
suites: [
require('./push-payload-relationships/push-payload')
require('./push-payload-relationships-self/push-payload')
]
}
);
66 changes: 66 additions & 0 deletions benchmarks/micro/push-payload-relationships-self/push-payload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
var name = 'pushPayload relationship-simple (complex-self)';

function fn() {
store.pushPayload('person', payload);
}

module.exports.fn = fn;
module.exports.name = name;
module.exports.setup = function() {
function generatePeople(from, to) {
var result = [];

for (var i = from; i < to; i++) {
result.push({
id: i,
firstName: Math.random().toString(36).substring(7),
lastName: Math.random().toString(36).substring(7),
age: Math.random() * 100,
born: Math.random() * 1000,
isInDebt: Math.round(Math.random(0, 1)),
description: Math.random().toString(36).substring(7),
friends: [i + 1, i + 2, i + 3, i + 4, i + 5, i +6, i + 7, to + i + 1, to + i + 2, to + i + 3, to + i + 4, to +i + 5]
});
}

return result;
}

if (!this.____setup) {
var Person = DS.Model.extend({
firstName: DS.attr(),
lastName: DS.attr(),
friends: DS.hasMany('person', { async: true })
});

var container = new Ember.Container();

container.register('store:main', DS.Store);
container.register('model:person', Person);
container.register('serializer:application', DS.RESTSerializer);
container.register('adapter:application', DS.RESTAdapter);

var store = container.lookup('store:main');

// ... TODO: why does benchmark JS do crazy shit
Object.defineProperty(this, '____setup', {
enumerable: false,
value:{
id: 0,
Person: Person,
container: container,
store: store
}}
);
}

var setup = this.____setup;
var payload, id, type, attrs;
var store = setup.store;

store.typeMapFor('person').records.length = 0;

payload = {
people: generatePeople(0, this.distribution)
};
}

0 comments on commit dd1b773

Please sign in to comment.