Console.log (v26)

Revision 26 of this benchmark created on


Setup

class Logger {
  static set productionMode(isProduction) {
    if (isProduction) {
      Logger.log = () => {};
      Logger.error = () => {};
      Logger.info = () => {};
      Logger.warn = () => {};
    } else {
      Logger.log = console.log;
      Logger.error = console.error;
      Logger.info = console.info;
      Logger.warn = console.warn;
    }
  }

  static log(){}

  static error(){}

  static info(){}

  static warn(){}
}

Logger.productionMode = true;

class Logger2 {
  static set productionMode(isProduction) {
    if (isProduction) {
      Logger2.log = () => {};
      Logger2.error = () => {};
      Logger2.info = () => {};
      Logger2.warn = () => {};
    } else {
      Logger2.log = console.log;
      Logger2.error = console.error;
      Logger2.info = console.info;
      Logger2.warn = console.warn;
    }
  }

  static log(){}

  static error(){}

  static info(){}

  static warn(){}
}

Logger2.productionMode = false;

Test runner

Ready to run.

Testing in
TestOps/sec
Logger production mode (empty function)
Logger.log('Logging stuff');
ready
Logger debug mode (console.log)
Logger2.log('Logging stuff');
ready

Revisions

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