Error stack access

Benchmark created on


Setup

class CustomError extends Error {
  constructor(message) {
    super(message);
    this.name = "CustomError";
  }
}

class CustomError2 {
  constructor(message, err) {
    this.name = "CustomError";
    this.message = message;
    this.err = err;
  }
  get stack() {
  	return this.err.stack;
  }
}
Reflect.setPrototypeOf(CustomError2.prototype, Error.prototype);

class CustomError3 extends Error {
  constructor(message) {
    super(message);
    this.name = "CustomError";
    this.stack2 = this.stack;
  }
}

Test runner

Ready to run.

Testing in
TestOps/sec
Default
new CustomError("Test error");
new CustomError("Test error 2");
new CustomError("Test error 3");
new CustomError("Test error 4");
new CustomError("Test error 5");
new CustomError("Test error 6").stack;
ready
new Error().stack
new CustomError2("T2", new Error());
new CustomError2("T3", new Error());
new CustomError2("T4", new Error());
new CustomError2("T5", new Error());
new CustomError2("T6", new Error());
new CustomError2("T7", new Error()).stack;
ready
Eager access
new CustomError3("Test error");
new CustomError3("Test error 2");
new CustomError3("Test error 3");
new CustomError3("Test error 4");
new CustomError3("Test error 5");
new CustomError3("Test error 6").stack;
ready

Revisions

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