Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function benchmark() {
- var testObject = {
- prop1: 4,
- prop2: 4,
- prop3: 4,
- prop4: 4,
- prop5: 4,
- prop6: 4,
- prop7: 4,
- prop8: 4,
- prop9: 4,
- prop10: 4,
- prop11: 4,
- prop12: 4,
- prop13: 4,
- prop14: 4,
- prop15: 4,
- prop16: 4,
- prop17: 4,
- prop18: 4,
- prop19: 4,
- prop20: 4,
- prop21: 4,
- prop22: 4,
- prop23: 4,
- prop24: 4,
- prop25: 4,
- prop26: 4,
- prop27: 4,
- prop28: 4,
- prop29: 4,
- prop: 3
- };
- function monomorphic(a) {
- return a.prop + a.prop;
- }
- function megamorphic(a) {
- return a.prop + a.prop;
- }
- var IC_filler = 100000000,
- bench = 10000000;
- var objs = [{
- prop: 3
- }, {
- prop3: 4,
- prop: 3,
- prop2: 4
- }, {
- prop4: 4,
- prop2: 4,
- prop: 3,
- prop5: 6
- },
- testObject, {
- prop7: 15,
- prop30: 12,
- prop314: 4,
- prop34: 15,
- prop: 3
- }
- ];
- var l = IC_filler;
- while (l--) {
- var index = Math.random() * objs.length | 0;
- megamorphic(objs[index]);
- }
- var l = IC_filler;
- while (l--) {
- monomorphic(testObject);
- }
- var now = Date.now(),
- l = bench;
- while (l--) {
- if (megamorphic(testObject) !== 6) {
- die();
- }
- }
- print("Megamorphic", Date.now() - now);
- var now = Date.now(),
- l = bench;
- while (l--) {
- if (monomorphic(testObject) !== 6) {
- die();
- }
- }
- print("Monomorphic", Date.now() - now);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement