Getter vs method vs property performance

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Case #1 a function that returns a string
class UseCase {
  code() { return 'string_with_use_case_name' }
}

let useCase = new UseCase()
useCase.code()
ready
Case #2 using getter to get the use case name
class UseCase {
  get code() { return 'string_with_use_case_name' }
}

let useCase = new UseCase()
useCase.code
ready
Case #3 using property to get the use case name
class UseCase {
  constructor() { 
    this.code = 'string_with_use_case_name'
  }
}

let useCase = new UseCase()
useCase.code
ready
Case #4 using static property to get the use case name
class UseCase {
  static code = 'string_with_use_case_name'
}

let useCase = new UseCase()
UseCase.code
ready

Revisions

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