jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script src="https://underscorejs.org/underscore.js">
</script>
<script src="https://backbonejs.org/backbone.js">
</script>
<script src="https://dhruvaray.github.com/backbone-associations/backbone-associations.js">
</script>
<script src="https://raw.github.com/PaulUithol/Backbone-relational/master/backbone-relational.js">
</script>
var _getDepartments = function(){
var loc1 = {
add1 : "P.O Box 3899",
zip: "94404",
state : "CA"
};
var loc2 = {
add1 : "P.O Box 4899",
zip: "95502",
state : "CA"
};
return [
{
name : 'R&D',
number : '23',
locations : [
loc1,
loc2
]
},
{
name : 'Marketing',
number : '24',
locations : [
loc1,
loc2
]
}
];
};
var getEmployee = function(count) {
!count && (count = 10);
var result = {
name: 'comp' + count,
employees: []
};
var departmentData = _getDepartments ();
for (var i = 0; i < count; i++) {
var emp = {
fname: 'fname' + i,
lname: 'lname' + i,
age: (function() {
var age = parseInt(Math.random() * 100);
return age < 20 ? age + 20 : age > 65 ? 65 : age;
})(),
sex: (function() {
return (parseInt(Math.random() * 100) % 2) ? 'M' : 'F';
})(),
works_for: (function() {
return departmentData[(parseInt(Math.random() * 100) % 2)];
})()
};
result.employees.push(emp);
}
return result;
}
// Associated Model
var associatedModel = {};
associatedModel.Location = Backbone.AssociatedModel.extend({
defaults: {
add1: "",
add2: null,
zip: "",
state: ""
}
});
associatedModel.Department = Backbone.AssociatedModel.extend({
relations: [{
type: Backbone.Many,
key: 'locations',
relatedModel: associatedModel.Location
}],
defaults: {
name: '',
locations: [],
number: -1
}
});
associatedModel.Employee = Backbone.AssociatedModel.extend({
relations: [{
type: Backbone.One,
key: 'works_for',
relatedModel: associatedModel.Department
}],
validate: function(attr) {
return (attr.sex && attr.sex != "M" && attr.sex != "F") ? "invalid sex value" : undefined;
},
defaults: {
sex: 'M',
//{F,M}
age: 0,
fname: "",
lname: "",
works_for: {}
}
});
associatedModel.Company = Backbone.AssociatedModel.extend({
relations: [{
type: Backbone.Many,
key: 'employees',
relatedModel: associatedModel.Employee
}],
defaults: {
name: '',
employees: []
}
});
// Relational Model
var relationalModel = {};
relationalModel.Location = Backbone.RelationalModel.extend({
defaults: {
add1: "",
add2: null,
zip: "",
state: ""
}
});
relationalModel.Department = Backbone.RelationalModel.extend({
relations: [{
type: Backbone.HasMany,
key: 'locations',
relatedModel: relationalModel.Location
}],
defaults: {
name: '',
locations: [],
number: -1
}
});
relationalModel.Employee = Backbone.RelationalModel.extend({
relations: [{
type: Backbone.HasOne,
key: 'works_for',
relatedModel: relationalModel.Department
}],
validate: function(attr) {
return (attr.sex && attr.sex != "M" && attr.sex != "F") ? "invalid sex value" : undefined;
},
defaults: {
sex: 'M',
//{F,M}
age: 0,
fname: "",
lname: "",
works_for: {}
}
});
relationalModel.Company = Backbone.RelationalModel.extend({
relations: [{
type: Backbone.HasMany,
key: 'employees',
relatedModel: relationalModel.Employee
}],
defaults: {
name: '',
employees: []
}
});
var employeeCollection = getEmployee(100);
Ready to run.
Test | Ops/sec | |
---|---|---|
backbone-associations |
| ready |
backbone-relational |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.