Skip to content

Instantly share code, notes, and snippets.

@Aschen
Created January 29, 2022 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Aschen/f8a67978ec759499b1530d5ee70a4350 to your computer and use it in GitHub Desktop.
Save Aschen/f8a67978ec759499b1530d5ee70a4350 to your computer and use it in GitHub Desktop.
Reflect.defineProperty
/**
$ 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