/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var benchmark1; var benchmark2; var loop = 1000000 var time // test execution time with approach a time = new Date().getTime() function ClassA( name ) { this.name = name } ClassA.prototype.init = function( index ) { this.name += index } for( var i=0;i<loop;i++ ) { var a = new ClassA( 'A' ) a.init( i ) } benchmark1 = new Date().getTime() - time // test execution time with approach b time = new Date().getTime() function ClassB( name ) { var o = {} o.name = name o.init = com_classb_init return o } function com_classb_init( index ) { this.name += index } for( var i=0;i<loop;i++ ) { var b = ClassB( 'B' ) b.init( i ) } benchmark2 = new Date().getTime() - time alert( benchmark1+", "+benchmark2 )
URL: oojs