Last active
March 7, 2018 13:14
-
-
Save manufitoussi/31f0d093162989bc3a0a20a7d46d80fe to your computer and use it in GitHub Desktop.
benchmark multiple props
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default { | |
CONTAINERS_COUNT: 1000, | |
PROPS_COUNT: 100 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember' | |
import Container from 'twiddle/objects/container' | |
import EmberContainer from 'twiddle/objects/ember-container' | |
import Constants from 'twiddle/constants' | |
//Ember.assert = () => {}; | |
const CONTAINERS_COUNT = Constants.CONTAINERS_COUNT; | |
const PROPS_COUNT = Constants.PROPS_COUNT; | |
///// | |
class ClassProperty { | |
get value() { | |
return this._value; | |
} | |
constructor(value) { | |
this._value = value; | |
} | |
}; | |
const classPropsConfig = {}; | |
for(var p=0;p<PROPS_COUNT;p++) { | |
const value = 'class property ' + p; | |
classPropsConfig['prop'+p] = Ember.computed({ | |
get() { | |
return new ClassProperty(value); | |
} | |
}); | |
} | |
const ClassContainer = Container.extend(classPropsConfig); | |
////// | |
const createNativeProperty = function(value) { | |
return { | |
_value: value, | |
value() { | |
return this._value; | |
} | |
}; | |
}; | |
const nativePropsConfig = {}; | |
for(var p=0;p<PROPS_COUNT;p++) { | |
const value = 'native property ' + p; | |
nativePropsConfig['prop'+p] = Ember.computed({ | |
get() { | |
return createNativeProperty(value); | |
} | |
}); | |
} | |
const NativeContainer = Container.extend(nativePropsConfig); | |
////// | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
emberContainers: Em.computed({ | |
get() { | |
return []; | |
} | |
}).readOnly(), | |
nativeContainers: Em.computed({ | |
get() { | |
return []; | |
} | |
}).readOnly(), | |
classContainers: Em.computed({ | |
get() { | |
return []; | |
} | |
}).readOnly(), | |
time: null, | |
onInit: Em.on('init', function() { | |
console.group('init'); | |
console.time('emberContainers'); | |
for(var i=0;i<CONTAINERS_COUNT;i++) { | |
this.get('emberContainers').pushObject(EmberContainer.create({ _numero: i+1 })); | |
} | |
console.timeEnd('emberContainers'); | |
console.time('nativeContainers'); | |
for(var i=0;i<CONTAINERS_COUNT;i++) { | |
this.get('nativeContainers').pushObject(NativeContainer.create({ _numero: i+1 })); | |
} | |
console.timeEnd('nativeContainers'); | |
console.time('classContainers'); | |
for(var i=0;i<CONTAINERS_COUNT;i++) { | |
this.get('classContainers').pushObject(ClassContainer.create({ _numero: i+1 })); | |
} | |
console.timeEnd('classContainers'); | |
console.groupEnd(); | |
console.group('assignation'); | |
console.time('emberContainers'); | |
const emberContainers = this.get('emberContainers'); | |
emberContainers.forEach(c => { | |
//console.group('emberContainer ' + c.get('_numero')); | |
for(var p=0;p<PROPS_COUNT;p++) { | |
//console.log('prop' + p, c.get('prop' + p + '.value')); | |
c.get('prop' + p + '.value'); | |
} | |
//console.groupEnd(); | |
}); | |
console.timeEnd('emberContainers'); | |
console.time('nativeContainers'); | |
this.get('nativeContainers').forEach(c => { | |
//console.group('nativeContainer ' + c.get('_numero')); | |
for(var p=0;p<PROPS_COUNT;p++) { | |
//console.log('prop' + p, c.get('prop' + p).value()); | |
c.get('prop' + p).value(); | |
} | |
//console.groupEnd(); | |
}); | |
console.timeEnd('nativeContainers'); | |
console.time('classContainers'); | |
this.get('classContainers').forEach(c => { | |
//console.group('classContainer ' + c.get('_numero')); | |
for(var p=0;p<PROPS_COUNT;p++) { | |
//console.log('prop' + p, c.get('prop' + p + '.value')); | |
c.get('prop' + p + '.value'); | |
} | |
//console.groupEnd(); | |
}); | |
console.timeEnd('classContainers'); | |
console.groupEnd(); | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember' | |
export default Ember.Object.extend({ | |
_numero: -1, | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember' | |
import Container from 'twiddle/objects/container' | |
import Constants from 'twiddle/constants' | |
const EmberProperty = Ember.Object.extend({ | |
value: null | |
}); | |
const emberPropsConfig = {}; | |
for(var p=0; p<Constants.PROPS_COUNT; p++) { | |
const value = 'ember property ' + p; | |
emberPropsConfig['prop' + p] = Ember.computed({ | |
get() { | |
return EmberProperty.create({ | |
value: value | |
}); | |
} | |
}); | |
} | |
export default Container.extend(emberPropsConfig) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.13.0", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.16.2", | |
"ember-template-compiler": "2.16.2", | |
"ember-testing": "2.16.2" | |
}, | |
"addons": { | |
"ember-data": "2.16.3" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment