object.create vs extends (v2)

Revision 2 of this benchmark created on


Preparation HTML

<script>
class CustomError extends Error {
	constructor(message, category, stack, customData, level) {
        super(message); // 调用父类的构造函数
        this.category = category;
        this.stack = stack
        this.customData = customData;
        this.level = level;
    }
}
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Object.create
const err = Object.create(Error.prototype, {
	level: { value: 'info' },
	category: { value: 'foo' },
	message: { value: 'message message' },
	stack: { value: 'stack stack stack' },
	customData: { value: {
		tag1: 'tag1',
		tag2: 'tag2',
	}},
});
err.toString();
ready
extends
const err = new CustomError('message message', 'foo', 'stack stack stack', {
		tag1: 'tag1',
		tag2: 'tag2',
	}, 'info');
	
err.toString();
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.