Created
January 29, 2022 15:18
-
-
Save Aschen/f8a67978ec759499b1530d5ee70a4350 to your computer and use it in GitHub Desktop.
Reflect.defineProperty
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
/** | |
$ node node/reflect.js | |
Reflect x 3,102,490 ops/sec ±5.31% (78 runs sampled) | |
Normal x 61,204,978 ops/sec ±5.73% (86 runs sampled) | |
Fastest is Normal | |
*/ | |
const {Benchmark} = require('benchmark'); | |
var suite = new Benchmark.Suite; | |
class ReflectMe { | |
constructor () { | |
Reflect.defineProperty(this, '_name', { | |
writable: true, | |
}); | |
} | |
} | |
class Normal { | |
constructor () { | |
this.name = 'aschen' | |
} | |
} | |
let ret; | |
// add tests | |
suite | |
.add('Reflect', function() { | |
ret = new ReflectMe(); | |
}) | |
.add('Normal', function() { | |
ret = new Normal(); | |
}) | |
// add listeners | |
.on('cycle', function(event) { | |
console.log(String(event.target)); | |
}) | |
.on('complete', function() { | |
console.log('Fastest is ' + this.filter('fastest').map('name')); | |
}) | |
// run async | |
.run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment