Tests:
  • class

    x
     
    const reportsData = Array(1000).map((_, index) => ({
        user: {
            id: index,
            name: 'user' + index
        }
    }));
    class Report {
        constructor(report) { this.report = report; }
      
        reporterId() { this.report.user.id; }
        reporterName() { this.report.user.name; }
    }
    const classReports = reportsData.map(data => new Report(data));
    classReports.forEach(report => console.log(report.reporterId, reporter.name))
  • object

     
    const reportsData = Array(1000).map((_, index) => ({
        user: {
            id: index,
            name: 'user' + index
        }
    }));
    const createReport = (report) => {
        return {
            ...report,
          
            get reporterId() { return this.user.id },
            get reporterName() { return this.user.name },
        }
    }
    const objectReports = reportsData.map(data => createReport(data));
    objectReports.forEach(report => console.log(report.reporterId, reporter.name))
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    class
    object

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 months ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Chrome 133 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
class 125958.2 Ops/sec
object 150189.4 Ops/sec