Skip to content

Instantly share code, notes, and snippets.

@trshafer
Created October 18, 2013 00:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trshafer/7034620 to your computer and use it in GitHub Desktop.
Save trshafer/7034620 to your computer and use it in GitHub Desktop.
Benchmark for model store checking params
var BaseModel, ModelStore, modelUtils, _;
ModelStore = require('../shared/store/model_store');
BaseModel = require('../shared/base/model');
modelUtils = require('../shared/modelUtils');
_ = require('underscore');
util = require('util');
function MyModel() {
MyModel.super_.apply(this, arguments);
}
util.inherits(MyModel, BaseModel);
function App() {}
modelUtils.addClassMapping(modelUtils.modelName(MyModel), MyModel);
app = new App;
store = new ModelStore({
app: app
});
times = 100000
_(times).times(function(n){
var modelAttrs = {
foo: 'bar'+n,
id: n
};
model = new MyModel(modelAttrs);
store.set(model);
});
function test(tester){
start = Date.now()
result = tester()
end = Date.now()
if (result)
console.log('searched through '+times+ ' records and took '+ (end - start) + ' milliseconds');
else
console.error('NOT FOUND')
}
console.log('starting test')
test(function(){
return store.find('my_model', {foo: 'bar1'});
})
test(function(){
return store.find('my_model', {foo: 'bar99999'});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment